packagecom.ilirium.client; |
importjava.io.ByteArrayOutputStream; |
importjava.io.FileNotFoundException; |
importjava.io.FileOutputStream; |
importjava.io.IOException; |
importjava.io.PrintStream; |
importjava.math.BigInteger; |
importjava.security.InvalidKeyException; |
importjava.security.KeyPair; |
importjava.security.KeyPairGenerator; |
importjava.security.NoSuchAlgorithmException; |
importjava.security.PublicKey; |
importjava.security.SecureRandom; |
importjava.security.Signature; |
importjava.security.SignatureException; |
importjava.util.Base64; |
importsun.security.util.DerOutputStream; |
importsun.security.x509.AlgorithmId; |
importsun.security.x509.X500Name; |
/** |
* |
* @author [email protected] |
*/ |
publicclassCertificateSigningRequestUsingSunJDK { |
publicstaticvoidmain(String[] args) throwsNoSuchAlgorithmException, IOException, InvalidKeyException, SignatureException { |
// generate RSA key pair |
KeyPair keypair = generateKeyPair(); |
// create Certficate Request Info |
X500Name x500Name =newX500Name('CN=Test,OU=Test,O=Test,L=Test,S=Test,C=Test'); |
byte[] certReqInfo = createCertificationRequestInfo(x500Name, keypair.getPublic()); |
// generate Signature over Certficate Request Info |
String algorithm ='SHA1WithRSA'; |
Signature signature =Signature.getInstance(algorithm); |
signature.initSign(keypair.getPrivate()); |
signature.update(certReqInfo); |
byte[] certReqInfoSignature = signature.sign(); |
// create PKCS#10 Certificate Signing Request (CSR) |
byte[] csrDEREncoded = createCertificationRequestValue(certReqInfo, algorithm, certReqInfoSignature); |
String csrPEMEncoded = createPEMFormat(csrDEREncoded); |
// write to file |
writeToFile(csrDEREncoded, 'D:csr.der'); |
writeToFile(csrPEMEncoded.getBytes(), 'D:csr.pem'); |
} |
privatestaticKeyPairgenerateKeyPair() throwsNoSuchAlgorithmException { |
KeyPairGenerator keyGen =KeyPairGenerator.getInstance('RSA'); |
keyGen.initialize(2048, newSecureRandom()); |
KeyPair keypair = keyGen.generateKeyPair(); |
return keypair; |
} |
publicstaticStringcreatePEMFormat(byte[] data) { |
finalByteArrayOutputStream out =newByteArrayOutputStream(); |
finalPrintStream ps =newPrintStream(out); |
ps.println('-----BEGIN NEW CERTIFICATE REQUEST-----'); |
ps.println(Base64.getMimeEncoder().encodeToString(data)); |
ps.println('-----END NEW CERTIFICATE REQUEST-----'); |
return out.toString(); |
} |
publicstaticbyte[] createCertificationRequestInfo(X500Namex500Name, PublicKeypublicKey) throwsIOException { |
finalDerOutputStream der1 =newDerOutputStream(); |
der1.putInteger(BigInteger.ZERO); |
x500Name.encode(der1); |
der1.write(publicKey.getEncoded()); |
// der encoded certificate request info |
finalDerOutputStream der2 =newDerOutputStream(); |
der2.write((byte) 48, der1); |
return der2.toByteArray(); |
} |
publicstaticbyte[] createCertificationRequestValue(byte[] certReqInfo, StringsignAlgo, byte[] signature) throwsIOException, NoSuchAlgorithmException { |
finalDerOutputStream der1 =newDerOutputStream(); |
der1.write(certReqInfo); |
// add signature algorithm identifier, and a digital signature on the certification request information |
AlgorithmId.get(signAlgo).encode(der1); |
der1.putBitString(signature); |
// final DER encoded output |
finalDerOutputStream der2 =newDerOutputStream(); |
der2.write((byte) 48, der1); |
return der2.toByteArray(); |
} |
privatestaticvoidwriteToFile(byte[] data, Stringfile) throwsFileNotFoundException, IOException { |
try (FileOutputStream out =newFileOutputStream(file)) { |
out.write(data); |
} |
} |
} |
Jun 28, 2012 i have rsa key pair generated in HSM PKCS#11 and i want to create a PKCS#10 certificate request (CSR) however, bouncycastle opensource java requires Publickey and privateKey, i can retrieve the modulus and exponent from HSM to form the public key again but what about the Private key? Hello,I'am testing your IDPrime 840(Applet ver: Id Prime Java Card 4.1.2 F) and 841(Applet ver: Id Prime Java Card 4.0.2 K) smart cards. I received the information that in order to generate keys (for example RSA) or use the remaining crypto possibilities of the card, I should use the PKCS # 11 libraries.
Age of empires 3 product key generator online. This should be your intention too, as a user, to fully evaluate Age Of Empires III 3 withoutrestrictions and then decide.If you are keeping the software and want to use it longer than its trial time, we strongly encourage you purchasing the license keyfrom Age official website.
These are:. In- Lab recovery: If there is any physical damage to your storage device then the lab experts retrieve your data efficiently. Recovery Software: If any of your files have been deleted or formatted then by using the recovery software you can get it back. Seagate Recovery Services Review:Seagate offers three services to recover your data. Seagate file recovery registration key generator for sale. Seagate ensures that in any circumstances if you lose your data, then you have multiple options to recover it and get back to work.