Exemple #1
0
        /**
         * generate a signature for the message we've been loaded with using
         * the key we were initialised with.
         */
        public byte[] generateSignature()
        {
            if (forSigning)
            {
                MemoryStream        bOut = new MemoryStream();
                DEROutputStream     dOut = new DEROutputStream(bOut);
                ASN1EncodableVector v    = new ASN1EncodableVector();

                byte[] dig = new byte[digest.getDigestSize()];
                digest.doFinal(dig, 0);

                BigInteger[] sig = dsaSigner.generateSignature(dig);

                v.add(new DERInteger(sig[0]));
                v.add(new DERInteger(sig[1]));

                dOut.writeObject(new DERSequence(v));
                dOut.Flush();

                byte[] output = bOut.ToArray();
                dOut.Close();
                return(output);
            }
            throw new Exception("DSADigestSigner initialised for verification..");
        }
Exemple #2
0
        /// <summary>
        /// Get the DER Encoded PKCS10 Certification Request.
        /// </summary>
        /// <returns>A byte array.</returns>
        public byte[] getEncoded()
        {
            MemoryStream    mStr   = new MemoryStream();
            DEROutputStream derOut = new DEROutputStream(mStr);

            derOut.writeObject(new CertificationRequest(reqInfo, sigAlgId, sigBits));
            derOut.Flush();
            byte[] _out = mStr.ToArray();
            mStr.Close();
            return(_out);
        }
Exemple #3
0
        private byte[] derEncode(
            byte[]  hash)
        {
            MemoryStream    bOut  = new MemoryStream();
            DEROutputStream dOut  = new DEROutputStream(bOut);
            DigestInfo      dInfo = new DigestInfo(algId, hash);

            dOut.writeObject(dInfo);
            dOut.Flush();

            return(bOut.ToArray());
        }
Exemple #4
0
        /// <summary>
        /// Verify PKCS10 Cert Reqest is valid.
        /// </summary>
        /// <returns>true = valid.</returns>
        public bool verify()
        {
            Signer sig = null;

            sig = SignerUtil.getSigner(sigAlgId.getObjectId());

            sig.init(false, getPublicKey());

            MemoryStream    mStr   = new MemoryStream();
            DEROutputStream derOut = new DEROutputStream(mStr);

            derOut.writeObject(reqInfo);
            derOut.Flush();
            byte[] b = mStr.ToArray();
            sig.update(b, 0, b.Length);
            mStr.Close();

            return(sig.verifySignature(sigBits.getBytes()));
        }