private static byte[] CreateSignature(byte[] data, CngKey key) { ECDsaCng signingAlgo = new ECDsaCng(key); byte[] signature = signingAlgo.SignData(data); signingAlgo.Clear(); return(signature); }
static byte[] CreateSignature(byte[] data, CngKey key) { byte[] signature; var signingAlg = new ECDsaCng(key); signature = signingAlg.SignData(data); signingAlg.Clear(); return(signature); }
public byte[] CreateSignature(byte[] data, CngKey key) { byte[] signature; using (var signingAlg = new ECDsaCng(key)) { signature = signingAlg.SignData(data, HashAlgorithmName.SHA512); signingAlg.Clear(); } return(signature); }
public static byte[] CreateSignature(byte[] data, CngKey key) { // 创建签名 byte[] signature; using (var signingAlg = new ECDsaCng(key)) { signature = signingAlg.SignData(data); signingAlg.Clear(); } return(signature); }
private void удалениеПарыКлючейToolStripMenuItem_Click(object sender, EventArgs e) { if (MessageBox.Show("Будет удалена пара ключей авторизованного пользователя.\nБудет произведена деавторизация.\nТекстовое поле будет очищено. Продолжить?", "Предупреждение", MessageBoxButtons.OKCancel) == DialogResult.OK) { Visible = false; DeleteDirectory(PK_store_path + "\\" + current_user); ecdsaCng.Key.Delete(); ecdsaCng.Clear(); Auth(); Visible = true; } }
static bool VerifySignature(byte[] data, byte[] signature, byte[] pubKey) { bool retValue = false; using (CngKey key = CngKey.Import(pubKey, CngKeyBlobFormat.GenericPublicBlob)) using (var signingAlg = new ECDsaCng(key)) { retValue = signingAlg.VerifyData(data, signature); signingAlg.Clear(); } return(retValue); }
/// <summary> /// 使用私钥签名 /// </summary> public static byte[] SignData(byte[] data, string keyName) { // 打开密钥 CngKey cngKey = CngKey.Open(keyName); // 签名 ECDsaCng ecdsa = new ECDsaCng(cngKey); byte[] signature = ecdsa.SignData(data); ecdsa.Clear(); cngKey.Dispose(); return(signature); }
private bool VerifySignaure(CngKey key, byte[] data, byte[] signature, byte[] pubkey) { bool retValue = false; using (ECDsaCng signingAlg = new ECDsaCng(key)) { retValue = signingAlg.VerifyData(data, signature); signingAlg.Clear(); } return(retValue); }
//创建签名 private static byte[] CreateSignature(byte[] data, CngKey key) { byte[] signature; //key是CngKey类型,包含了公钥和私钥 //将key传入ECDsaCng得到加密算法 using (var signingAlg = new ECDsaCng(key)) { //使用 signingAlg.SignData 对 要签名的内容以及私钥进行签名 signature = signingAlg.SignData(data, HashAlgorithmName.SHA512); signingAlg.Clear(); } return(signature); }
/// <summary> /// 使用公钥验证签名 /// </summary> public static bool VerifyData(byte[] data, byte[] signature, byte[] publicKey) { bool verified = false; // 导入公钥 CngKey cngKey = CngKey.Import(publicKey, CngKeyBlobFormat.EccPublicBlob); // 验证签名 ECDsaCng ecdsa = new ECDsaCng(cngKey); verified = ecdsa.VerifyData(data, signature); ecdsa.Clear(); cngKey.Dispose(); return(verified); }
private byte[] CreateSignature(byte[] data, CngKey key) { /*Имея в распоряжении пару ключей, отправитель может создать подпись с помощью класса ECDsaCng. * Конструктор этого класса принимает объект CngKey, в котором содержится открытый и секретный ключи. * Далее этот секретный ключ используется для подписания данных вызовом метода SignData() */ byte[] signature; var signingAlg = new ECDsaCng(key); signature = signingAlg.SignData(data); signingAlg.Clear(); return(signature); }
private byte[] CreateSignature(byte[] data, CngKey key) { byte[] signature; using (var signingAlg = new ECDsaCng(key)) { #if NET46 signature = signingAlg.SignData(data); signingAlg.Clear(); #else signature = signingAlg.SignData(data, HashAlgorithmName.SHA512); #endif } return(signature); }
/// <summary> /// 有了密钥对,Alice就可以使用ECDsaCng类创建签名了。 /// 这个类的构造函数从Alice那里接收包含公钥和私钥的CngKey类。 /// 再使用私钥,通过SignData0方法给数据签名。SignData()方法在.NET core中略有不同。.NETcore需要如下算法 /// </summary> /// <param name="aliceData"></param> /// <param name="_aliceKeySignature"></param> /// <returns></returns> private static byte[] CreateSignature(byte[] aliceData, CngKey _aliceKeySignature) { byte[] signature; using (var signingAlg = new ECDsaCng(_aliceKeySignature)) { #if NET46 signature = signingAlg.SignData(aliceData); signingAlg.Clear(); #else signature = signingAlg.SignData(aliceData, HashAlgorithmName.SHA512); #endif } return(signature); }
public bool VerifySignature(byte[] data, byte[] signature, byte[] pubKeys) { bool retValue = false; using (CngKey key = CngKey.Import(pubKeys, CngKeyBlobFormat.GenericPrivateBlob)) { using (var signungAlg = new ECDsaCng(key)) { retValue = signungAlg.VerifyData(data, signature, HashAlgorithmName.SHA512); signungAlg.Clear(); } return(retValue); } }
//验证签名 private static bool VerifySignature(byte[] data, byte[] signature, byte[] pubKey) { bool retValue = false; //使用 CngKey.Import 导入CngKey对象,的到公钥 using (CngKey key = CngKey.Import(pubKey, CngKeyBlobFormat.GenericPublicBlob)) //将公钥传入ECDsaCng得到解密签名算法 using (var signinAlg = new ECDsaCng(key)) { //然后使用signinAlg.VerifyData来验证签名 retValue = signinAlg.VerifyData(data, signature, HashAlgorithmName.SHA512); signinAlg.Clear(); } return(retValue); }
public bool VerifySignature(string password, byte[] signature, byte[] salt) { bool retValue = false; using (CngKey key = CngKey.Import(salt, CngKeyBlobFormat.GenericPublicBlob)) using (var signingAlg = new ECDsaCng(key)) { //#if NET46 retValue = signingAlg.VerifyData(Encoding.UTF8.GetBytes(password), signature); signingAlg.Clear(); //#else // retValue = signingAlg.VerifyData(data, signature, HashAlgorithmName.SHA512); //#endif } return(retValue); }
/// <summary> /// 要验证签名是否真的来自于Alice,Bob使用Alice的公钥检查签名。包含公钥blob的字节数组可以用静态方法Import()导入CngKey对象。 /// 然后使用ECDsaCng类,调用VerifyData()方法来验证签名。 /// </summary> /// <param name="aliceData"></param> /// <param name="aliceSignature"></param> /// <param name="_alicePublicKeyBob"></param> /// <returns></returns> private static bool VerifySignature(byte[] data, byte[] signature, byte[] pubKey) { bool retValue = false; using (CngKey key = CngKey.Import(pubKey, CngKeyBlobFormat.GenericPublicBlob)) using (var signingAlg = new ECDsaCng(key)) { #if NET46 retValue = signingAlg.VerifyData(data, signature); signingAlg.Clear(); #else retValue = signingAlg.VerifyData(data, signature, HashAlgorithmName.SHA512); #endif } return(retValue); }
/// <summary> /// 创建签名 /// </summary> /// <param name="data"></param> /// <param name="key"></param> /// <returns></returns> private byte[] CreateSignature(byte[] data, CngKey key) { byte[] signature; //使用ECDsaCng创建签名,ECDsaCng的构造函数接收包含公钥和私钥的CngKey类对象 using (ECDsaCng signingAlg = new ECDsaCng(key)) { #if NET46 signature = signingAlg.SignData(data); signingAlg.Clear(); #else //对数据进行签名(加密) signature = signingAlg.SignData(data, HashAlgorithmName.SHA512); #endif } return(signature); }
private bool VerifySignature(byte[] data, byte[] signature, byte[] pubKey) { /*Для проверки, действительно ли подпись принадлежит отправителю, получатель извлекает ее с применением полученного * от отправителя открытого ключа. Для этого сначала массив байтов, содержащий этот открытый ключ, импортируется * в объект CngKey с помощью статического метода Import(), а затем для верификации подписи вызывается метод VerifyData() * класса ECDsaCng */ bool retValue = false; using (CngKey key = CngKey.Import(pubKey, CngKeyBlobFormat.GenericPublicBlob)) { var signingAlg = new ECDsaCng(key); retValue = signingAlg.VerifyData(data, signature); signingAlg.Clear(); } return(retValue); }
static byte[] CreateSignature(byte[] data, CngKey key) { byte[] signature; //这里直接用 CngKey 加密 //using(var signingAlg = new ECDsaCng(key)) //{ // signature = signingAlg.SignData(data); // signingAlg.Clear(); //} //这里用私钥重新生成CngKey对象 using (CngKey pKey = CngKey.Import(aliceSecKeyBlob, CngKeyBlobFormat.GenericPrivateBlob)) { using (var signingAlg = new ECDsaCng(pKey)) { signature = signingAlg.SignData(data); signingAlg.Clear(); } } return(signature); }
public void UseEncrpyting() { // Init key CngKey key = CngKey.Create(CngAlgorithm.ECDsaP521); byte[] pubKeyBlob = key.Export(CngKeyBlobFormat.GenericPublicBlob); byte[] myData = Encoding.UTF8.GetBytes("Hello there"); using (var signingAlgorithm = new ECDsaCng(key)) { byte[] signature = signingAlgorithm.SignData(myData, HashAlgorithmName.SHA512); Console.WriteLine(Encoding.UTF8.GetString(signature)); using (CngKey k = CngKey.Import(pubKeyBlob, CngKeyBlobFormat.GenericPublicBlob)) { bool ret = signingAlgorithm.VerifyData(myData, signature, HashAlgorithmName.SHA512); Console.WriteLine($"Encoding success={ret}"); } signingAlgorithm.Clear(); } }