// NOTE: this method can work with ANY configured (OID in machine.config)
        // HashAlgorithm descendant
        public byte[] SignData(byte[] buffer, int offset, int count, object halg)
        {
            HashAlgorithm hash = GetHash(halg);

            byte[] toBeSigned = hash.ComputeHash(buffer, offset, count);
            return(PKCS1.Sign_v15(this, hash, toBeSigned));
        }
        // NOTE: this method can work with ANY configured (OID in machine.config)
        // HashAlgorithm descendant
        public byte[] SignData(Stream inputStream, object halg)
        {
            HashAlgorithm hash = GetHash(halg);

            byte[] toBeSigned = hash.ComputeHash(inputStream);
            return(PKCS1.Sign_v15(this, hash, toBeSigned));
        }
예제 #3
0
        public void PKCS15_SignAndVerify_UnknownHash()
        {
            // this hash algorithm isn't known from CryptoConfig so no OID is available
            MD5SHA1 hash = new MD5SHA1();

            byte[] value   = GetValue(hash.HashSize >> 3);
            byte[] unknown = PKCS1.Sign_v15(rsa, hash, value);
            Assert.IsTrue(PKCS1.Verify_v15(rsa, hash, value, unknown), "Verify");
        }
        public byte[] SignHash(byte[] rgbHash, string str)
        {
            if (rgbHash == null)
            {
                throw new ArgumentNullException("rgbHash");
            }
            // Fx 2.0 defaults to the SHA-1
            string        hashName = (str == null) ? "SHA1" : GetHashNameFromOID(str);
            HashAlgorithm hash     = HashAlgorithm.Create(hashName);

            return(PKCS1.Sign_v15(this, hash, rgbHash));
        }
예제 #5
0
 public static SecureBuffer CreateSignature(SignatureAndHashAlgorithm type, HashAlgorithm hash, SecureBuffer hashData, AsymmetricAlgorithm key)
 {
     if (!VerifyHashType(type, hash))
     {
         throw new TlsException(AlertDescription.IlegalParameter);
     }
     if (type.Signature == SignatureAlgorithmType.Rsa)
     {
         return(new SecureBuffer(PKCS1.Sign_v15((RSA)key, hash, hashData.Buffer)));
     }
     else
     {
         throw new NotSupportedException();
     }
 }
예제 #6
0
        public byte[] Sign(byte[] data, byte[] userID)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            if (userID == null)
            {
                throw new ArgumentNullException("userID");
            }
            RSA rsaa = RSA.Create();

            rsaa.ImportParameters(loggedInUsers [userID]);
            return(PKCS1.Sign_v15(rsaa, SHA256.Create(), data));
        }
예제 #7
0
        public override byte[] Sign()
        {
            try {
                ms.Position = 0;
                HashAlgorithm hash       = HashAlgorithm.Create("SHA1");
                byte[]        toBeSigned = hash.ComputeHash(ms);
                ms = new MemoryStream();
                return(PKCS1.Sign_v15(rsa, hash, toBeSigned));

//				byte[] res = rsa.SignData (ms, "sha1");
//				return res;
            } catch (Exception ex) {
                Console.WriteLine(ex);
                throw;
            }
        }
예제 #8
0
 public override byte[] CreateSignature(byte[] rgbHash)
 {
     if (key == null)
     {
         throw new CryptographicUnexpectedOperationException("The key is a null reference");
     }
     if (hash == null)
     {
         throw new CryptographicUnexpectedOperationException("The hash algorithm is a null reference.");
     }
     if (rgbHash == null)
     {
         throw new ArgumentNullException("The rgbHash parameter is a null reference.");
     }
     return(PKCS1.Sign_v15(key, hash, rgbHash));
 }
예제 #9
0
        public byte[][] Sign(byte[] data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            List <byte[]> rv = new List <byte[]> ();

            foreach (var userData in loggedInUsers)
            {
                RSA rsaa = RSA.Create();
                rsaa.ImportParameters(userData.Value);
                byte[] sig = PKCS1.Sign_v15(rsaa, SHA256.Create(), data);
                rv.Add(userData.Key);
                rv.Add(sig);
            }
            return(rv.ToArray());
        }
        public override byte[] CreateSignature(byte[] rgbHash)
        {
            if (rsa == null)
            {
                throw new CryptographicUnexpectedOperationException(
                          Locale.GetText("No key pair available."));
            }
            if (hash == null)
            {
                throw new CryptographicUnexpectedOperationException(
                          Locale.GetText("Missing hash algorithm."));
            }
            if (rgbHash == null)
            {
                throw new ArgumentNullException("rgbHash");
            }

            return(PKCS1.Sign_v15(rsa, hash, rgbHash));
        }