/// <summary> /// 公開鍵と秘密鍵を作成して返す /// </summary> /// <param name="publicKey">作成された公開鍵</param> /// <param name="privateKey">作成された秘密鍵</param> public static void CreateKeys(out byte[] publicKey, out byte[] privateKey) { #if Mono throw new NotSupportedException(); #else CngKeyCreationParameters ckcp = new CngKeyCreationParameters(); ckcp.ExportPolicy = CngExportPolicies.AllowPlaintextExport; ckcp.KeyUsage = CngKeyUsages.KeyAgreement; using (CngKey ck = CngKey.Create(CngAlgorithm.ECDiffieHellmanP521, null, ckcp)) using (ECDiffieHellmanCng ecdh = new ECDiffieHellmanCng(ck)) { publicKey = Encoding.ASCII.GetBytes(ecdh.ToXmlString(ECKeyXmlFormat.Rfc4050)); privateKey = ecdh.Key.Export(CngKeyBlobFormat.Pkcs8PrivateBlob); } #endif }