public bool SignatureDeformatter(string p_strHashbyteDeformatter, string p_strDeformatterData) { bool result; try { byte[] rgbHash = System.Convert.FromBase64String(p_strHashbyteDeformatter); System.Security.Cryptography.RSACryptoServiceProvider rSACryptoServiceProvider = new System.Security.Cryptography.RSACryptoServiceProvider(); rSACryptoServiceProvider.FromXmlString(this.p_strKeyPublic); System.Security.Cryptography.RSAPKCS1SignatureDeformatter rSAPKCS1SignatureDeformatter = new System.Security.Cryptography.RSAPKCS1SignatureDeformatter(rSACryptoServiceProvider); rSAPKCS1SignatureDeformatter.SetHashAlgorithm("MD5"); byte[] rgbSignature = System.Convert.FromBase64String(p_strDeformatterData); if (rSAPKCS1SignatureDeformatter.VerifySignature(rgbHash, rgbSignature)) { result = true; } else { result = false; } } catch { result = false; } return(result); }
private static async System.Threading.Tasks.Task <ResultType> TaskMain(Fee.Crypt.OnCryptTask_CallBackInterface a_callback_interface, byte[] a_binary, byte[] a_signature_binary, string a_key, Fee.TaskW.CancelToken a_cancel) #endif { ResultType t_ret; { t_ret.verify = false; t_ret.errorstring = null; } try{ //ハッシュの計算。 byte[] t_hash_binary = null; using (System.Security.Cryptography.SHA1Managed t_sha1 = new System.Security.Cryptography.SHA1Managed()){ t_hash_binary = t_sha1.ComputeHash(a_binary); } if (t_hash_binary == null) { t_ret.verify = false; t_ret.errorstring = "Task_VerifySignaturePublicKey : hash == null"; } else { using (System.Security.Cryptography.RSACryptoServiceProvider t_rsa = new System.Security.Cryptography.RSACryptoServiceProvider()){ t_rsa.FromXmlString(a_key); //証明書検証。 System.Security.Cryptography.RSAPKCS1SignatureDeformatter t_deformatter = new System.Security.Cryptography.RSAPKCS1SignatureDeformatter(t_rsa); t_deformatter.SetHashAlgorithm("SHA1"); t_ret.verify = t_deformatter.VerifySignature(t_hash_binary, a_signature_binary); } } }catch (System.Exception t_exception) { t_ret.verify = false; t_ret.errorstring = "Task_VerifySignaturePublicKey : " + t_exception.Message; } if (a_cancel.IsCancellationRequested() == true) { t_ret.verify = false; t_ret.errorstring = "Task_VerifySignaturePublicKey : Cancel"; a_cancel.ThrowIfCancellationRequested(); } if (t_ret.verify == false) { if (t_ret.errorstring == null) { t_ret.errorstring = "Task_VerifySignaturePublicKey : null"; } } return(t_ret); }
public static bool VerifyDigitalSignature(byte[] bytes, byte[] signature, string publicKey) { using (var sha = new System.Security.Cryptography.SHA256Managed()) { var hashData = sha.ComputeHash(bytes); using (var rsa = new System.Security.Cryptography.RSACryptoServiceProvider()) { rsa.FromXmlString(publicKey); var rsaDeformatter = new System.Security.Cryptography.RSAPKCS1SignatureDeformatter(rsa); rsaDeformatter.SetHashAlgorithm("SHA256"); return(rsaDeformatter.VerifySignature(hashData, signature)); } } }
public bool verify(byte[] sig) { cs.Close(); System.Security.Cryptography.RSACryptoServiceProvider RSA = new System.Security.Cryptography.RSACryptoServiceProvider(); RSA.ImportParameters(RSAKeyInfo); System.Security.Cryptography.RSAPKCS1SignatureDeformatter RSADeformatter = new System.Security.Cryptography.RSAPKCS1SignatureDeformatter(RSA); RSADeformatter.SetHashAlgorithm("SHA1"); long i = 0; long j = 0; byte[] tmp; //Util.Dump("c:\\sig.bin", sig); if (sig[0] == 0 && sig[1] == 0 && sig[2] == 0) { long i1 = (sig[i++] << 24) & 0xff000000; long i2 = (sig[i++] << 16) & 0x00ff0000; long i3 = (sig[i++] << 8) & 0x0000ff00; long i4 = (sig[i++]) & 0x000000ff; j = i1 | i2 | i3 | i4; i += j; i1 = (sig[i++] << 24) & 0xff000000; i2 = (sig[i++] << 16) & 0x00ff0000; i3 = (sig[i++] << 8) & 0x0000ff00; i4 = (sig[i++]) & 0x000000ff; j = i1 | i2 | i3 | i4; tmp = new byte[j]; Array.Copy(sig, i, tmp, 0, j); sig = tmp; } //System.out.println("j="+j+" "+Integer.toHexString(sig[0]&0xff)); //return signature.verify(sig); bool verify = RSADeformatter.VerifySignature(sha1, sig); return(verify); }
public bool verify(byte[] sig) { cs.Close(); System.Security.Cryptography.RSACryptoServiceProvider RSA = new System.Security.Cryptography.RSACryptoServiceProvider(); RSA.ImportParameters(RSAKeyInfo); System.Security.Cryptography.RSAPKCS1SignatureDeformatter RSADeformatter = new System.Security.Cryptography.RSAPKCS1SignatureDeformatter(RSA); RSADeformatter.SetHashAlgorithm("SHA1"); long i=0; long j=0; byte[] tmp; //Util.Dump("c:\\sig.bin", sig); if(sig[0]==0 && sig[1]==0 && sig[2]==0) { long i1 = (sig[i++]<<24)&0xff000000; long i2 = (sig[i++]<<16)&0x00ff0000; long i3 = (sig[i++]<<8)&0x0000ff00; long i4 = (sig[i++])&0x000000ff; j = i1 | i2 | i3 | i4; i+=j; i1 = (sig[i++]<<24)&0xff000000; i2 = (sig[i++]<<16)&0x00ff0000; i3 = (sig[i++]<<8)&0x0000ff00; i4 = (sig[i++])&0x000000ff; j = i1 | i2 | i3 | i4; tmp=new byte[j]; Array.Copy(sig, i, tmp, 0, j); sig=tmp; } //System.out.println("j="+j+" "+Integer.toHexString(sig[0]&0xff)); //return signature.verify(sig); bool verify = RSADeformatter.VerifySignature(sha1, sig); return verify; }
public bool verify(byte[] sig) { cs.Close(); System.Security.Cryptography.RSACryptoServiceProvider RSA = new System.Security.Cryptography.RSACryptoServiceProvider(); RSA.ImportParameters(RSAKeyInfo); System.Security.Cryptography.RSAPKCS1SignatureDeformatter RSADeformatter = new System.Security.Cryptography.RSAPKCS1SignatureDeformatter(RSA); RSADeformatter.SetHashAlgorithm("SHA1"); int i=0; int j=0; byte[] tmp; if(sig[0]==0 && sig[1]==0 && sig[2]==0) { j=(int)((sig[i++]<<24)&0xff000000)|(byte)((sig[i++]<<16)&0x00ff0000)|(byte) ((sig[i++]<<8)&0x0000ff00)|(byte)((sig[i++])&0x000000ff); i+=j; j=(int)((sig[i++]<<24)&0xff000000)|(byte)((sig[i++]<<16)&0x00ff0000)|(byte) ((sig[i++]<<8)&0x0000ff00)|(byte)((sig[i++])&0x000000ff); tmp=new byte[j]; Array.Copy(sig, i, tmp, 0, j); sig=tmp; } //System.out.println("j="+j+" "+Integer.toHexString(sig[0]&0xff)); //return signature.verify(sig); return RSADeformatter.VerifySignature(sha1, sig); }