示例#1
0
        public virtual ISigner CreateVerifyer(AsymmetricKeyParameter publicKey)
        {
            ISigner s = new DsaDigestSigner(CreateDsaImpl(), new Sha1Digest());

            s.Init(false, publicKey);
            return(s);
        }
示例#2
0
        protected virtual ISigner MakeSigner(IDigest d, bool forSigning, ICipherParameters cp)
        {
            ISigner s = new DsaDigestSigner(CreateDsaImpl(), d);

            s.Init(forSigning, cp);
            return(s);
        }
        private ISigner GetSigner(TSignatureAlgorithm signatureAlgorithm, THashAlgorithm hashAlgorithm, AsymmetricKeyParameter serverPrivateKey)
        {
            ISigner result = null;

            switch (signatureAlgorithm)
            {
            case TSignatureAlgorithm.Anonymous:
                break;

            case TSignatureAlgorithm.RSA:
                break;

            case TSignatureAlgorithm.DSA:
                break;

            case TSignatureAlgorithm.ECDSA:
                result = new DsaDigestSigner(new ECDsaSigner(), GetDigest(hashAlgorithm));
                break;

            default:
                break;
            }
            result.Init(true, serverPrivateKey);
            //result.Init(true, new ParametersWithRandom(serverPrivateKey, this.mContext.SecureRandom));
            return(result);
        }
示例#4
0
        protected virtual ISigner MakeSigner(SignatureAndHashAlgorithm algorithm, bool raw, bool forSigning, ICipherParameters cp)
        {
            if (algorithm != null != TlsUtilities.IsTlsV12(mContext))
            {
                throw new InvalidOperationException();
            }
            if (algorithm != null && algorithm.Signature != SignatureAlgorithm)
            {
                throw new InvalidOperationException();
            }
            byte   hashAlgorithm = algorithm?.Hash ?? 2;
            object digest2;

            if (raw)
            {
                IDigest digest = new NullDigest();
                digest2 = digest;
            }
            else
            {
                digest2 = TlsUtilities.CreateHash(hashAlgorithm);
            }
            IDigest digest3 = (IDigest)digest2;
            ISigner signer  = new DsaDigestSigner(CreateDsaImpl(hashAlgorithm), digest3);

            signer.Init(forSigning, MakeInitParameters(forSigning, cp));
            return(signer);
        }
示例#5
0
            public ISigner CreateEngine(EngineUsage usage)
            {
                ISigner sig = new DsaDigestSigner(new DsaSigner(new HMacDsaKCalculator(FipsShs.CreateHmac(parameters.DigestAlgorithm))), FipsShs.CreateDigest(parameters.DigestAlgorithm));

                sig.Init((usage == EngineUsage.SIGNING), sigParams);

                return(sig);
            }
示例#6
0
            public ISigner CreateEngine(EngineUsage usage)
            {
                ISigner sig = new DsaDigestSigner(DSA_PROVIDER.CreateEngine(usage), CreateDigest(parameters.DigestAlgorithm));

                sig.Init((usage == EngineUsage.SIGNING), sigParams);

                return(sig);
            }
示例#7
0
        public byte[] CalculateRawSignature(AsymmetricKeyParameter privateKey, byte[] md5andsha1)
        {
            // Note: Only use the SHA1 part of the hash
            ISigner sig = new DsaDigestSigner(new DsaSigner(), new NullDigest());

            sig.Init(true, privateKey);
            sig.BlockUpdate(md5andsha1, 16, 20);
            return(sig.GenerateSignature());
        }
示例#8
0
        public virtual byte[] CalculateRawSignature(SecureRandom random,
                                                    AsymmetricKeyParameter privateKey, byte[] md5andsha1)
        {
            // Note: Only use the SHA1 part of the hash
            ISigner sig = new DsaDigestSigner(CreateDsaImpl(), new NullDigest());

            sig.Init(true, new ParametersWithRandom(privateKey, random));
            sig.BlockUpdate(md5andsha1, 16, 20);
            return(sig.GenerateSignature());
        }
        public byte[] Sign(byte[] data, string privateKey)
        {
            var key = PrivateKeyFactory.CreateKey(Convert.FromBase64String(privateKey));

            var dsaDigestSigner = new DsaDigestSigner(new DsaSigner(), new Sha1Digest());

            dsaDigestSigner.Init(true, key);

            dsaDigestSigner.BlockUpdate(data, 0, data.Length);
            return(dsaDigestSigner.GenerateSignature());
        }
        public bool Verify(byte[] data, byte[] signature, string publicKey)
        {
            var key = PublicKeyFactory.CreateKey(Convert.FromBase64String(publicKey));

            var dsaDigestSigner = new DsaDigestSigner(new DsaSigner(), new Sha1Digest());

            dsaDigestSigner.Init(false, key);

            dsaDigestSigner.BlockUpdate(data, 0, data.Length);

            return(dsaDigestSigner.VerifySignature(signature));
        }
示例#11
0
        /// <summary>
        /// Gets the signing stream.
        /// </summary>
        /// <returns></returns>
        public HashingStream GetSigningStream(Keyczar keyczar)
        {
            var digest = PublicKey.GetDigest();
            var signer = new DsaDigestSigner(new DsaSigner(), digest);
            var param  = new DsaPrivateKeyParameters(X.ToBouncyBigInteger(),
                                                     new DsaParameters(PublicKey.P.ToBouncyBigInteger(),
                                                                       PublicKey.Q.ToBouncyBigInteger(),
                                                                       PublicKey.G.ToBouncyBigInteger()));

            signer.Init(forSigning: true, parameters: new ParametersWithRandom(param, Secure.Random));

            return(new DigestStream(signer));
        }
示例#12
0
        protected virtual ISigner MakeSigner(SignatureAndHashAlgorithm algorithm, bool raw, bool forSigning, ICipherParameters cp)
        {
            if (algorithm != null != TlsUtilities.IsTlsV12(this.mContext))
            {
                throw new InvalidOperationException();
            }
            if (algorithm != null && algorithm.Signature != this.SignatureAlgorithm)
            {
                throw new InvalidOperationException();
            }
            byte    hashAlgorithm = (algorithm == null) ? 2 : algorithm.Hash;
            IDigest digest        = raw ? new NullDigest() : TlsUtilities.CreateHash(hashAlgorithm);
            ISigner signer        = new DsaDigestSigner(this.CreateDsaImpl(hashAlgorithm), digest);

            signer.Init(forSigning, this.MakeInitParameters(forSigning, cp));
            return(signer);
        }
示例#13
0
        protected virtual ISigner MakeSigner(SignatureAndHashAlgorithm algorithm, bool raw, bool forSigning, ICipherParameters cp)
        {
            //IL_0014: Unknown result type (might be due to invalid IL or missing references)
            //IL_002b: Unknown result type (might be due to invalid IL or missing references)
            if (algorithm != null != TlsUtilities.IsTlsV12(mContext))
            {
                throw new InvalidOperationException();
            }
            if (algorithm != null && algorithm.Signature != SignatureAlgorithm)
            {
                throw new InvalidOperationException();
            }
            byte    hashAlgorithm = algorithm?.Hash ?? 2;
            IDigest digest        = (raw ? new NullDigest() : TlsUtilities.CreateHash(hashAlgorithm));
            ISigner signer        = new DsaDigestSigner(CreateDsaImpl(hashAlgorithm), digest);

            signer.Init(forSigning, MakeInitParameters(forSigning, cp));
            return(signer);
        }
示例#14
0
        protected virtual ISigner MakeSigner(SignatureAndHashAlgorithm algorithm, bool raw, bool forSigning,
                                             ICipherParameters cp)
        {
            if ((algorithm != null) != TlsUtilities.IsTlsV12(mContext))
            {
                throw new InvalidOperationException();
            }

            if (algorithm != null && algorithm.Signature != SignatureAlgorithm)
            {
                throw new InvalidOperationException();
            }

            byte    hashAlgorithm = algorithm == null ? HashAlgorithm.sha1 : algorithm.Hash;
            IDigest d             = raw ? new NullDigest() : TlsUtilities.CreateHash(hashAlgorithm);

            ISigner s = new DsaDigestSigner(CreateDsaImpl(hashAlgorithm), d);

            s.Init(forSigning, MakeInitParameters(forSigning, cp));
            return(s);
        }
示例#15
0
        /// <summary>
        /// Signs the passed in data with a private key
        /// </summary>
        /// <param name="privateKey">the private key used to create the signature</param>
        /// <param name="data">The data to sign</param>
        /// <returns>the signature as a byte array</returns>
        public byte[] Sign(byte[] privateKey, byte[] data)
        {
            var signer  = new DsaDigestSigner(new DsaSigner(), new Sha1Digest());
            var privKey = (DsaPrivateKeyParameters)CreateAsymmetricKeyParameterFromPrivateKeyInfo(privateKey);

            signer.Init(true, privKey);
            signer.BlockUpdate(data, 0, data.Length);
            byte[] signature;
            try
            {
                signature = signer.GenerateSignature();
            }
            catch (Exception exception)
            {
                string message = "Signature Failure!\n" +
                                 $"{exception.Message}.\n" +
                                 $"The private key file is corrupted, verify private key file or try another key.\n" +
                                 $"If all fails create a new key pair.";
                throw new CryptoException(message, exception);
            }
            return(signature);
        }
示例#16
0
        /// <summary>
        /// Verifies a signature to be authentic
        /// </summary>
        /// <param name="originalSignature">The signature which is be verified</param>
        /// <param name="publicKey">the public key used for the verification</param>
        /// <param name="data">the data which is signed</param>
        /// <returns>true if signature is authentic, false if not</returns>
        public bool Verify(byte[] originalSignature, byte[] publicKey, byte[] data)
        {
            var signer = new DsaDigestSigner(new DsaSigner(), new Sha1Digest());

            DsaPublicKeyParameters pubKey = null;

            try
            {
                pubKey = (DsaPublicKeyParameters)CreateAsymmetricKeyParameterFromPublicKeyInfo(publicKey);
            }
            catch (Exception exception)
            {
                string message = "Public Key Creation Failure!\n" +
                                 $"{exception.Message}.\n" +
                                 $"The public key file is corrupted, verify public key file or try another key.\n" +
                                 $"If all fails create a new key pair.";
                throw new CryptoException(message, exception);
            }
            signer.Init(false, pubKey);
            signer.BlockUpdate(data, 0, data.Length);
            return(signer.VerifySignature(originalSignature));
        }