예제 #1
0
        /// <summary>
        /// get csr
        /// </summary>
        /// <param name="issuerName"></param>
        /// <returns></returns>
        public static Tuple <string, AsymmetricKeyParameter> GetCsr(string issuerName)
        {
            //generate KeyPair
            var keyGenerator             = new ECKeyPairGenerator();
            ECKeyGenerationParameters pa = new ECKeyGenerationParameters(SecObjectIdentifiers.SecP256r1, new SecureRandom());

            keyGenerator.Init(pa);
            var keypair = keyGenerator.GenerateKeyPair();

            //domain name of CSR file
            X509Name principal = new X509Name(string.Format("CN={0},OU=client,O=BSN", string.IsNullOrEmpty(issuerName) ? "test02@app0001202004161020152918451" : issuerName));

            //load public key
            SubjectPublicKeyInfo subjectPublicKeyInfo = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(keypair.Public);

            CertificationRequestInfo info = new CertificationRequestInfo(principal, subjectPublicKeyInfo, new DerSet());

            //signature
            byte[] bs = ECDSAHelper.CsrSignData(info.GetEncoded(Asn1Encodable.Der), keypair.Private, pa.DomainParameters.N);
            //generate csr object
            Pkcs10CertificationRequest p10 = new Pkcs10CertificationRequest(new CertificationRequest
                                                                                (info, new AlgorithmIdentifier(X9ObjectIdentifiers.ECDsaWithSha256),
                                                                                new DerBitString(bs)).GetEncoded());

            //generate csr string
            Org.BouncyCastle.Utilities.IO.Pem.PemObject pemCSR = new Org.BouncyCastle.Utilities.IO.Pem.PemObject("CERTIFICATE REQUEST", p10.GetEncoded());

            StringWriter str = new StringWriter();

            Org.BouncyCastle.Utilities.IO.Pem.PemWriter pemCsr = new Org.BouncyCastle.Utilities.IO.Pem.PemWriter(str);
            pemCsr.WriteObject(pemCSR);
            pemCsr.Writer.Flush();

            return(new Tuple <string, AsymmetricKeyParameter>(str.ToString(), keypair.Private));
        }
예제 #2
0
 public TransactionHeader(string mspid, string cert, string channelId)
 {
     if (cert.Contains(".pem"))
     {
         cert = ECDSAHelper.ReadPK(cert);
     }
     this.SetCreator(mspid, cert);
     SetTxId(RandomHelper.GetRandomNonceByte());
     this.ChannelID = channelId;
 }
예제 #3
0
        private static SignedProposal signProposal(Proposal proposal, string prikey)
        {
            var proposalBytes = Util.Marshal(proposal);
            var signature     = Util.ConvertToByteString(ECDSAHelper.SignData(proposalBytes, prikey));

            return(new SignedProposal()
            {
                ProposalBytes = proposalBytes,
                Signature = signature
            });
        }