public byte[] SignWithSHA1(byte[] data) { byte[] hash = new SHA1CryptoServiceProvider().ComputeHash(data); byte[] buf = new byte[hash.Length + PKIUtil.SHA1_ASN_ID.Length]; Array.Copy(PKIUtil.SHA1_ASN_ID, 0, buf, 0, PKIUtil.SHA1_ASN_ID.Length); Array.Copy(hash, 0, buf, PKIUtil.SHA1_ASN_ID.Length, hash.Length); BigInteger x = new BigInteger(buf); //Debug.WriteLine(x.ToHexString()); int padLen = (_publickey._n.bitCount() + 7) / 8; x = RSAUtil.PKCS1PadType1(x, padLen); byte[] result = Sign(x.getBytes()); return(result); }
public void VerifyWithSHA1(byte[] data, byte[] expected) { BigInteger result = VerifyBI(data); byte[] finaldata = RSAUtil.StripPKCS1Pad(result, 1).getBytes(); if (finaldata.Length != PKIUtil.SHA1_ASN_ID.Length + expected.Length) { throw new VerifyException("result is too short"); } else { byte[] r = new byte[finaldata.Length]; Array.Copy(PKIUtil.SHA1_ASN_ID, 0, r, 0, PKIUtil.SHA1_ASN_ID.Length); Array.Copy(expected, 0, r, PKIUtil.SHA1_ASN_ID.Length, expected.Length); if (SSHUtil.memcmp(r, finaldata) != 0) { throw new VerifyException("failed to verify"); } } }