private static X509Certificate createCertificate( AsymmetricCipherKeyPair pair, string country, string organization, string locality, string state, string emailAddress, string commonName, BigInteger serialNumber, AsymmetricCipherKeyPair signer) { Hashtable attrs = new Hashtable(); attrs.Add(X509Name.C, country); // Country attrs.Add(X509Name.O, organization); // Organization attrs.Add(X509Name.L, locality); // Locality attrs.Add(X509Name.ST, state); // State/Province attrs.Add(X509Name.EmailAddress, emailAddress); attrs.Add(X509Name.CN, commonName); // Common Name // Create a certificate X509V3CertificateGenerator certGen = new X509V3CertificateGenerator(); certGen.setSerialNumber(serialNumber); certGen.setIssuerDN(new X509Name(attrs)); certGen.setNotBefore(DateTime.Today.Subtract(new TimeSpan(1, 0, 0, 0))); certGen.setNotAfter(DateTime.Today.AddDays(365)); certGen.setSubjectDN(new X509Name(attrs)); certGen.setPublicKey(pair.getPublic()); certGen.setSignatureAlgorithm("SHA1WithRSAEncryption"); return(certGen.generateX509Certificate(signer.getPrivate())); }
public ScrambledKeyPair(AsymmetricCipherKeyPair pPair) { _pair = pPair; _publicKey = pPair.getPublic(); _scrambledModulus = scrambleModulus((_publicKey as RSAKeyParameters).getModulus()); _privateKey = pPair.getPrivate(); }
public ScrambledKeyPair(AsymmetricCipherKeyPair pPair) { _pair = pPair; AsymmetricKeyParameter publicKey = pPair.getPublic(); RSAKeyParameters rsaKeyParameters = publicKey as RSAKeyParameters; if (rsaKeyParameters != null) { ScrambledModulus = ScrambleModulus(rsaKeyParameters.getModulus()); } PrivateKey = pPair.getPrivate(); }
private RSAKeyParameters generateKeys() { RSAKeyPairGenerator kpg = new RSAKeyPairGenerator(); RSAKeyGenerationParameters parms = new RSAKeyGenerationParameters( BigInteger.valueOf(0x11), new SecureRandom(), keySize, certainty); kpg.init(parms); AsymmetricCipherKeyPair pair = kpg.generateKeyPair(); privateKey = (RSAKeyParameters)pair.getPrivate(); return((RSAKeyParameters)pair.getPublic()); }