概要
cscの作法、調べてみた。
練習問題やってみた。
練習問題
ファイルをhashしてvirustotalに投げて、判定せよ。
サンプルコード
using System.Collections;
using System.IO;
using System;
using System.Text;
using System.Linq;
using System.Security.Cryptography;
using LitJson;
using System.Net;
using System.Net.Http;
namespace app
{
class test0 {
static void Main(string[] args) {
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
if (args.Length == 0)
{
Console.WriteLine("cert0 file");
return;
}
byte[] byteValue = File.ReadAllBytes(args[0]);
SHA256 crypto = new SHA256CryptoServiceProvider();
byte[] hashValue = crypto.ComputeHash(byteValue);
var hash = String.Join("", hashValue.Select(x => x.ToString("x2")).ToArray());
Console.WriteLine(hash);
string url = "https://www.virustotal.com/vtapi/v2/file/report?apikey=******&resource=" + hash;
HttpClient client = new HttpClient();
string response = client.GetStringAsync(url).Result;
LitJson.JsonData json = LitJson.JsonMapper.ToObject(response);
try
{
Console.WriteLine("total: " + json["total"]);
Console.WriteLine("positive: " + json["positives"]);
}
catch (Exception ex)
{
Console.WriteLine("pass");
}
}
}
}
実行結果
>virustotal2 myenc.txt
pass
>
以上。