示例#1
0
        public byte[] PkcsSign(byte[] m, TpmAlgId hashAlg)
        {
            int k = KeySize;

            byte[]     em      = CryptoEncoders.Pkcs15Encode(m, k, hashAlg);
            BigInteger message = FromBigEndian(em);
            BigInteger sig     = BigInteger.ModPow(message, D, N);

            byte[] signature = ToBigEndian(sig, KeySize);
            return(signature);
        }
示例#2
0
        public bool PkcsVerify(byte[] m, byte[] s, TpmAlgId hashAlg)
        {
            if (s.Length != KeySize)
            {
                throw new Exception("Invalid signature");
            }
            int        k   = KeySize;
            BigInteger sig = FromBigEndian(s);
            BigInteger emx = BigInteger.ModPow(sig, E, N);

            byte[] emDecrypted = ToBigEndian(emx, KeySize);

            byte[] emPrime = CryptoEncoders.Pkcs15Encode(m, k, hashAlg);
            if (!Globs.ArraysAreEqual(emPrime, emDecrypted))
            {
                return(false);
            }
            return(true);
        }