Example usage for java.security KeyFactory generatePrivate

List of usage examples for java.security KeyFactory generatePrivate

Introduction

In this page you can find the example usage for java.security KeyFactory generatePrivate.

Prototype

public final PrivateKey generatePrivate(KeySpec keySpec) throws InvalidKeySpecException 

Source Link

Document

Generates a private key object from the provided key specification (key material).

Usage

From source file:org.ejbca.core.protocol.ws.client.CvcRequestCommand.java

/**
 * Runs the command//  w  w w.  j  a  v a 2 s  .  c  o m
 *
 * @throws IllegalAdminCommandException Error in command args
 * @throws ErrorAdminCommandException Error running command
 */
public void execute() throws IllegalAdminCommandException, ErrorAdminCommandException {

    try {
        if (args.length < 9 || args.length > 11) {
            getPrintStream().println("Number of arguments: " + args.length);
            usage();
            System.exit(-1); // NOPMD, this is not a JEE app
        }

        String username = args[ARG_USERNAME];
        String userpassword = args[ARG_PASSWORD];
        String dn = args[ARG_SUBJECTDN];
        String sequence = args[ARG_SEQUENCE];
        String signatureAlg = args[ARG_SIGNALG];
        String keySpec = args[ARG_KEYSPEC];
        boolean genrequest = args[ARG_GENREQ].equalsIgnoreCase("true");
        String basefilename = args[ARG_BASEFILENAME];
        String authSignKeyFile = null;
        if (args.length > (ARG_AUTHSIGNKEY)) {
            authSignKeyFile = args[ARG_AUTHSIGNKEY];
        }
        String authSignCertFile = null;
        if (args.length > (ARG_AUTHSIGNCERT)) {
            authSignCertFile = args[ARG_AUTHSIGNCERT];
        }

        getPrintStream().println("Enrolling user:");
        getPrintStream().println("Username: " + username);
        getPrintStream().println("Subject name: " + dn);
        getPrintStream().println("Sequence: " + sequence);
        getPrintStream().println("Signature algorithm: " + signatureAlg);
        getPrintStream().println("Key spec: " + keySpec);

        try {
            CryptoProviderTools.installBCProvider();

            String cvcreq = null;
            if (genrequest) {
                getPrintStream().println("Generating a new request with base filename: " + basefilename);
                // Generate keys for the request
                String keytype = "RSA";
                if (signatureAlg.contains("ECDSA")) {
                    keytype = "ECDSA";
                }
                KeyPair keyPair = KeyTools.genKeys(keySpec, keytype);
                String country = CertTools.getPartFromDN(dn, "C");
                String mnemonic = CertTools.getPartFromDN(dn, "CN");
                if (sequence.equalsIgnoreCase("null")) {
                    sequence = RandomStringUtils.randomNumeric(5);
                    getPrintStream().println("No sequence given, using random 5 number sequence: " + sequence);
                }
                //CAReferenceField caRef = new CAReferenceField(country,mnemonic,sequence);
                CAReferenceField caRef = null; // Don't create a caRef in the self signed request
                // We are making a self signed request, so holder ref is same as ca ref
                HolderReferenceField holderRef = new HolderReferenceField(country, mnemonic, sequence);
                CVCertificate request = CertificateGenerator.createRequest(keyPair, signatureAlg, caRef,
                        holderRef);
                byte[] der = request.getDEREncoded();
                if (authSignKeyFile != null) {
                    getPrintStream().println("Reading private key from pkcs8 file " + authSignKeyFile
                            + " to create an authenticated request");
                    byte[] keybytes = FileTools.readFiletoBuffer(authSignKeyFile);
                    KeyFactory keyfact = KeyFactory.getInstance(keytype, "BC");
                    PrivateKey privKey = keyfact.generatePrivate(new PKCS8EncodedKeySpec(keybytes));
                    KeyPair authKeyPair = new KeyPair(null, privKey); // We don't need the public key
                    // Default caRef if we do not pass in a certificate to get caRef from
                    CAReferenceField authCaRef = new CAReferenceField(country, mnemonic, sequence);
                    CVCertificate authCert = null;
                    if (authSignCertFile != null) {
                        getPrintStream().println("Reading cert from cvcert file " + authSignCertFile
                                + " to create an authenticated request");
                        CVCObject parsedObject = CvcPrintCommand.getCVCObject(authSignCertFile);
                        authCert = (CVCertificate) parsedObject;
                        String c = authCert.getCertificateBody().getHolderReference().getCountry();
                        String m = authCert.getCertificateBody().getHolderReference().getMnemonic();
                        String s = authCert.getCertificateBody().getHolderReference().getSequence();
                        authCaRef = new CAReferenceField(c, m, s);
                    }
                    CVCAuthenticatedRequest authRequest = CertificateGenerator
                            .createAuthenticatedRequest(request, authKeyPair, signatureAlg, authCaRef);
                    // Test to verify it yourself first
                    if (authCert != null) {
                        getPrintStream().println("Verifying the request before sending it...");
                        PublicKey pk = KeyTools.getECPublicKeyWithParams(
                                authCert.getCertificateBody().getPublicKey(), keySpec);
                        authRequest.verify(pk);
                    }
                    der = authRequest.getDEREncoded();
                }
                cvcreq = new String(Base64.encode(der));
                // Print the generated request to file
                FileOutputStream fos = new FileOutputStream(basefilename + ".cvreq");
                fos.write(der);
                fos.close();
                getPrintStream().println("Wrote binary request to: " + basefilename + ".cvreq");
                fos = new FileOutputStream(basefilename + ".pkcs8");
                fos.write(keyPair.getPrivate().getEncoded());
                fos.close();
                getPrintStream().println("Wrote private key in " + keyPair.getPrivate().getFormat()
                        + " format to to: " + basefilename + ".pkcs8");
            } else {
                // Read request from file
                getPrintStream().println("Reading request from filename: " + basefilename + ".cvreq");
                byte[] der = FileTools.readFiletoBuffer(basefilename + ".cvreq");
                cvcreq = new String(Base64.encode(der));
            }

            // Edit a user, creating it if it does not exist
            // Actually don't do that, leverage the existing commands and force to use the editUser command instead.
            // This also makes this CLI exactly represent the actual WS-API call 
            // getEjbcaRAWS().editUser(userdata);

            getPrintStream().println("Submitting CVC request for user '" + username + "'.");
            getPrintStream().println();
            // Use the request and request a certificate
            List<Certificate> resp = getEjbcaRAWS().cvcRequest(username, userpassword, cvcreq);

            // Handle the response
            Certificate cert = resp.get(0);
            byte[] b64cert = cert.getCertificateData();
            CVCObject parsedObject = CertificateParser.parseCertificate(Base64.decode(b64cert));
            CVCertificate cvcert = (CVCertificate) parsedObject;
            FileOutputStream fos = new FileOutputStream(basefilename + ".cvcert");
            fos.write(cvcert.getDEREncoded());
            fos.close();
            getPrintStream().println("Wrote binary certificate to: " + basefilename + ".cvcert");
            getPrintStream().println("You can look at the certificate with the command cvcwscli.sh cvcprint "
                    + basefilename + ".cvcert");
        } catch (AuthorizationDeniedException_Exception e) {
            getPrintStream().println("Error : " + e.getMessage());
        } catch (UserDoesntFullfillEndEntityProfile_Exception e) {
            getPrintStream()
                    .println("Error : Given userdata doesn't fullfill end entity profile. : " + e.getMessage());
        }

    } catch (Exception e) {
        if (e instanceof EjbcaException_Exception) {
            EjbcaException_Exception e1 = (EjbcaException_Exception) e;
            getPrintStream()
                    .println("Error code is: " + e1.getFaultInfo().getErrorCode().getInternalErrorCode());
        }
        throw new ErrorAdminCommandException(e);
    }
}

From source file:org.ejbca.core.protocol.ws.client.NestedCrmfRequestTestCommand.java

private void init(String args[]) {

    FileInputStream file_inputstream;
    try {/* w ww  .jav  a  2  s .c om*/
        String pwd = args[ARG_KEYSTOREPASSWORD];
        String certNameInKeystore = args[ARG_CERTNAMEINKEYSTORE];
        file_inputstream = new FileInputStream(args[ARG_KEYSTOREPATH]);
        KeyStore keyStore = KeyStore.getInstance("PKCS12");
        keyStore.load(file_inputstream, pwd.toCharArray());
        System.out.println("Keystore size " + keyStore.size());
        Enumeration aliases = keyStore.aliases();
        while (aliases.hasMoreElements()) {
            System.out.println(aliases.nextElement());
        }
        Key key = keyStore.getKey(certNameInKeystore, pwd.toCharArray());
        getPrintStream().println("Key information " + key.getAlgorithm() + " " + key.getFormat());
        PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(key.getEncoded());
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        innerSignKey = keyFactory.generatePrivate(keySpec);
        innerCertificate = keyStore.getCertificate(certNameInKeystore);
    } catch (FileNotFoundException e2) {
        e2.printStackTrace();
    } catch (KeyStoreException e) {
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (CertificateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (UnrecoverableKeyException e) {
        e.printStackTrace();
    } catch (InvalidKeySpecException e) {
        e.printStackTrace();
    }

    try {
        KeyPair outerSignKeys = KeyTools.genKeys("1024", "RSA");
        outerSignKey = outerSignKeys.getPrivate();
        X509Certificate signCert = CertTools.genSelfCert("CN=cmpTest,C=SE", 5000, null,
                outerSignKeys.getPrivate(), outerSignKeys.getPublic(),
                PKCSObjectIdentifiers.sha256WithRSAEncryption.getId(), true, "BC");

        writeCertificate(signCert, "/opt/racerts", "cmpTest.pem");

        /*
        ArrayList<Certificate> certCollection = new ArrayList<Certificate>();
        certCollection.add(signCert);
        byte[] pemRaCert = CertTools.getPEMFromCerts(certCollection);
                
        FileOutputStream out = new FileOutputStream(new File("/opt/racerts/cmpStressTest.pem"));
        out.write(pemRaCert);
        out.close();
        */
    } catch (NoSuchAlgorithmException e1) {
        e1.printStackTrace();
    } catch (NoSuchProviderException e1) {
        e1.printStackTrace();
    } catch (InvalidAlgorithmParameterException e1) {
        e1.printStackTrace();
    } catch (InvalidKeyException e) {
        e.printStackTrace();
    } catch (CertificateEncodingException e) {
        e.printStackTrace();
    } catch (SignatureException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        e.printStackTrace();
        //} catch (FileNotFoundException e) {
        //   e.printStackTrace();
        //} catch (IOException e) {
        //   e.printStackTrace();
        //} catch (CertificateException e) {
        //   e.printStackTrace();
    }

}

From source file:org.teknux.jettybootstrap.keystore.JettyKeystoreConvertorBuilder.java

public JettyKeystoreConvertorBuilder setPrivateKeyFromPKCS8(InputStream inputStream, String algorithm)
        throws JettyKeystoreException {
    try {/*from w  w w . j  a  v  a  2  s . co  m*/
        String contentKeyFile = IOUtils.toString(inputStream);

        Matcher contentKeyMatcher = PRIVATE_KEY_PATTERN.matcher(contentKeyFile);

        String contentKey;
        if (contentKeyMatcher.find()) {
            contentKey = contentKeyMatcher.group(1);
        } else {
            contentKey = contentKeyFile;
        }

        byte[] decodedKeyFile = Base64.decode(contentKey);

        KeyFactory keyFactory = KeyFactory.getInstance(algorithm);

        PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(decodedKeyFile);
        privateKey = keyFactory.generatePrivate(privateKeySpec);

        return this;

    } catch (IOException | NoSuchAlgorithmException | InvalidKeySpecException | DecoderException e) {
        throw new JettyKeystoreException(JettyKeystoreException.ERROR_LOAD_PRIVATE_KEY_PKCS8,
                "Can not load private key (PKCS8)", e);
    }
}

From source file:org.ow2.proactive.authentication.crypto.Credentials.java

/**
 * Retrieves a private key stored in a local file
 * <p>/* w w  w  .  jav  a 2  s  .com*/
 * Tries to guess the algorithm used for keypair generation which
 * is not included in the file. According to <a href="http://download.oracle.com/javase/1.5.0/docs/guide/security/CryptoSpec.html#AppA">Java Cryptography Specification</a>,
 * the algorithm can be only one of "RSA" or "DSA", so we can just try both using the
 * <code>algorithms</code> param. If the algorithm used to generate the key is neither RSA or DSA
 * (highly unlikely), this method cannot recreate the private key, but {@link #decrypt(String)}
 * maybe will.
 * 
 * @param privPath
 *            path to the private key on the local filesystem
 * @param algorithms a list of algorithms to try for creating the PK. Recommanded value:
 *          {"RSA","DSA"}
 * @return the key encapsulated in a regular JCE container
 * @throws KeyException
 *             the key could not be retrieved or is malformed, or the algorithm used for generation
 *             is not one of <code>algorithms</code>
 */
public static PrivateKey getPrivateKey(String privPath, String[] algorithms) throws KeyException {

    PrivateKey privKey = null;

    for (String algo : algorithms) {
        try {
            KeyFactory keyFactory;
            keyFactory = KeyFactory.getInstance(algo);

            // recover private key bytes
            byte[] bytes;
            try {
                File pkFile = new File(privPath);
                DataInputStream pkStream = new DataInputStream(new FileInputStream(pkFile));
                bytes = new byte[(int) pkFile.length()];
                pkStream.readFully(bytes);
                pkStream.close();
            } catch (Exception e) {
                throw new KeyException("Could not recover private key (algo=" + algo + ")", e);
            }

            // reconstruct private key
            PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(bytes);
            try {
                privKey = keyFactory.generatePrivate(privKeySpec);
            } catch (InvalidKeySpecException e) {
                throw new KeyException("Cannot re-generate private key  (algo=" + algo + ")", e);
            }
        } catch (Exception e) {
        }
    }

    if (privKey == null) {
        String str = "Could not generate Private Key (algorithms: ";
        for (String algo : algorithms) {
            str += algo + " ";
        }
        str += ")";
        throw new KeyException(str);
    }

    return privKey;
}

From source file:nl.b3p.viewer.stripes.CycloramaActionBean.java

private String getTIDFromBase64EncodedString(String base64Encoded, String token)
        throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException, SignatureException,
        UnsupportedEncodingException {

    String tid = null;/*  w  w w  .  j a  v a2s . c om*/
    Base64 encoder = new Base64();

    byte[] tempBytes = encoder.decode(base64Encoded.getBytes());

    KeyFactory rsaKeyFac = KeyFactory.getInstance("RSA");
    PKCS8EncodedKeySpec encodedKeySpec = new PKCS8EncodedKeySpec(tempBytes);
    RSAPrivateKey privKey = (RSAPrivateKey) rsaKeyFac.generatePrivate(encodedKeySpec);

    byte[] signature = sign(privKey, token);

    String base64 = new String(encoder.encode(signature));
    tid = URLEncoder.encode(token + "&" + base64, URL_ENCODING);

    return tid;
}

From source file:org.apache.cloudstack.network.ssl.CertServiceImpl.java

public PrivateKey parsePrivateKey(final String key) throws IOException {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(key));
    try (final PemReader pemReader = new PemReader(new StringReader(key));) {
        final PemObject pemObject = pemReader.readPemObject();
        final byte[] content = pemObject.getContent();
        final PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(content);
        final KeyFactory factory = KeyFactory.getInstance("RSA", "BC");
        return factory.generatePrivate(privKeySpec);
    } catch (NoSuchAlgorithmException | NoSuchProviderException e) {
        throw new IOException("No encryption provider available.", e);
    } catch (final InvalidKeySpecException e) {
        throw new IOException("Invalid Key format.", e);
    }//from  ww  w  . j a  va  2  s  .  c om
}

From source file:com.cws.esolutions.security.dao.keymgmt.impl.FileKeyManager.java

/**
 * @see com.cws.esolutions.security.dao.keymgmt.interfaces.KeyManager#returnKeys(java.lang.String)
 *//*from w w w .ja  v  a2s  .  c  o  m*/
public synchronized KeyPair returnKeys(final String guid) throws KeyManagementException {
    final String methodName = FileKeyManager.CNAME
            + "#returnKeys(final String guid) throws KeyManagementException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Value: {}", guid);
    }

    KeyPair keyPair = null;
    InputStream pubStream = null;
    InputStream privStream = null;

    final File keyDirectory = FileUtils.getFile(keyConfig.getKeyDirectory() + "/" + guid);

    try {
        if (!(keyDirectory.exists())) {
            throw new KeyManagementException("Configured key directory does not exist and unable to create it");
        }

        File publicFile = FileUtils
                .getFile(keyDirectory + "/" + guid + SecurityServiceConstants.PUBLICKEY_FILE_EXT);
        File privateFile = FileUtils
                .getFile(keyDirectory + "/" + guid + SecurityServiceConstants.PRIVATEKEY_FILE_EXT);

        if ((publicFile.exists()) && (privateFile.exists())) {
            privStream = new FileInputStream(privateFile);
            byte[] privKeyBytes = IOUtils.toByteArray(privStream);

            pubStream = new FileInputStream(publicFile);
            byte[] pubKeyBytes = IOUtils.toByteArray(pubStream);

            // files exist
            KeyFactory keyFactory = KeyFactory.getInstance(keyConfig.getKeyAlgorithm());

            // generate private key
            PKCS8EncodedKeySpec privateSpec = new PKCS8EncodedKeySpec(privKeyBytes);
            PrivateKey privKey = keyFactory.generatePrivate(privateSpec);

            // generate pubkey
            X509EncodedKeySpec publicSpec = new X509EncodedKeySpec(pubKeyBytes);
            PublicKey pubKey = keyFactory.generatePublic(publicSpec);

            // make the keypair
            keyPair = new KeyPair(pubKey, privKey);
        } else {
            // files dont exist
            throw new KeyManagementException("Failed to locate user keys");
        }
    } catch (FileNotFoundException fnfx) {
        throw new KeyManagementException(fnfx.getMessage(), fnfx);
    } catch (InvalidKeySpecException iksx) {
        throw new KeyManagementException(iksx.getMessage(), iksx);
    } catch (IOException iox) {
        throw new KeyManagementException(iox.getMessage(), iox);
    } catch (NoSuchAlgorithmException nsax) {
        throw new KeyManagementException(nsax.getMessage(), nsax);
    } finally {
        if (privStream != null) {
            IOUtils.closeQuietly(privStream);
        }

        if (pubStream != null) {
            IOUtils.closeQuietly(pubStream);
        }
    }

    return keyPair;
}

From source file:com.linkedin.drelephant.clients.azkaban.AzkabanWorkflowClient.java

/**
 * Decodes the encoded password using the _privateKey
 * @param encodedPassword//from   w w w. j a  va 2  s.com
 * @param _privateKey
 * @return The decoded password
 * @throws IOException
 * @throws NoSuchAlgorithmException
 * @throws InvalidKeySpecException
 * @throws NoSuchPaddingException
 * @throws InvalidKeyException
 * @throws IllegalBlockSizeException
 * @throws BadPaddingException
 */
private String decodeHeadlessChallenge(String encodedPassword, File _privateKey)
        throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException,
        InvalidKeyException, IllegalBlockSizeException, BadPaddingException {

    final String RSA = "RSA";
    final String ASCII = "US-ASCII";

    // Read private key from file
    FileInputStream fstream = new FileInputStream(_privateKey);
    byte[] sshPrivateKey = IOUtils.toByteArray(fstream);
    PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(sshPrivateKey);
    KeyFactory kf = KeyFactory.getInstance(RSA);
    PrivateKey privateKey = kf.generatePrivate(keySpec);

    // Init RSA decrypter with private key
    Cipher decryptCipher = Cipher.getInstance(RSA);
    decryptCipher.init(2, privateKey);

    // Convert base 64 password string to raw bytes
    byte[] rawBytes = org.apache.commons.codec.binary.Base64.decodeBase64(encodedPassword.getBytes(ASCII));

    // Decrypt the encoded raw bytes using decrypter
    byte[] decodedBytes = decryptCipher.doFinal(rawBytes);

    // Return decoded bytes as string
    return new String(decodedBytes, ASCII);
}

From source file:XmldapCertsAndKeys.java

public static RSAPrivateKey getXmldapPrivateKey() throws InvalidKeySpecException, NoSuchAlgorithmException {
    String exponentB64 = "AKh/FZVHiKxcIPA8g2mN8TUdMXuX58I7z4jS+57vYta387MG3DGZtQ/XXfHdPx9WjdoW0KWE2Pl5"
            + "SbOZW7tVcwigF88FrSJ5i6XDwUktmXjFwJM/TvUZlxWAKUdoOX8MC3DrAYZxeT3kC1mzAiBMPdC4"
            + "W4zNe7Zo0YgbsMzQZowVxZTP4GWa/L8o3adXTvdobP1nKW5buPj9vkgaGCTxE0vQzbuiGj1HRJe9"
            + "MRtvcU/I2shiIVE0F35wk8gw0FATtkvMpTpR12YVeo1JGZsHFQoD7gTD/n/NmC9Rjk2baYGj97hV"
            + "9EpDRcPNsMll2pVRy4Z45j2+t/yl8WjaqK5lhkE=";
    String modulusB64 = "ANMnkVA4xfpG0bLos9FOpNBjHAdFahy2cJ7FUwuXd/IShnG+5qF/z1SdPWzRxTtpFFyodtXlBUEI"
            + "biT+IbYPZF1vCcBrcFa8Kz/4rBjrpPZgllgA/WSVKjnJvw8q4/tO6CQZSlRlj/ebNK9VyT1kN+Mr"
            + "KV1SGTqaIJ2l+7Rd05WHscwZMPdVWBbRrg76YTfy6H/NlQIArNLZanPvE0Vd5QfD4ZyG2hTh3y7Z"
            + "lJAUndGJ/kfZw8sKuL9QSrh4eOTc280NQUmPGz6LP5MXNmu0RxEcomod1+ToKll90yEKFAUKuPYF"
            + "gm9J+vYm4tzRequLy/njteRIkcfAdcAtt6PCYjU=";
    byte[] exponentBytes = Base64.decode(exponentB64);
    byte[] modulusBytes = Base64.decode(modulusB64);
    BigInteger exponent = new BigInteger(1, exponentBytes);
    BigInteger modulus = new BigInteger(1, modulusBytes);
    RSAPrivateKeySpec ks = new RSAPrivateKeySpec(modulus, exponent);
    KeyFactory kf = KeyFactory.getInstance("RSA");
    return (RSAPrivateKey) kf.generatePrivate(ks);
}

From source file:XmldapCertsAndKeys.java

public static RSAPrivateKey getXmldapPrivateKey1() throws InvalidKeySpecException, NoSuchAlgorithmException {
    byte[] modulusBytes = { (byte) 0x00, (byte) 0xe2, (byte) 0x94, (byte) 0x9f, (byte) 0xaf, (byte) 0xd0,
            (byte) 0xa9, (byte) 0x36, (byte) 0x63, (byte) 0xfc, (byte) 0x15, (byte) 0xa8, (byte) 0x41,
            (byte) 0x5c, (byte) 0x4d, (byte) 0x14, (byte) 0x8d, (byte) 0x19, (byte) 0xd8, (byte) 0x05,
            (byte) 0xc8, (byte) 0xd5, (byte) 0xac, (byte) 0xf0, (byte) 0xb3, (byte) 0xe4, (byte) 0x72,
            (byte) 0xb8, (byte) 0x97, (byte) 0xa4, (byte) 0xeb, (byte) 0x43, (byte) 0x62, (byte) 0x6b,
            (byte) 0x04, (byte) 0x2b, (byte) 0x14, (byte) 0x02, (byte) 0xa4, (byte) 0xd0, (byte) 0xf8,
            (byte) 0x7e, (byte) 0xfd, (byte) 0x89, (byte) 0xd4, (byte) 0x89, (byte) 0x00, (byte) 0x27,
            (byte) 0xcd, (byte) 0xbb, (byte) 0x13, (byte) 0xfa, (byte) 0x3b, (byte) 0x99, (byte) 0x57,
            (byte) 0x4f, (byte) 0x14, (byte) 0xa5, (byte) 0xa3, (byte) 0xda, (byte) 0xd8, (byte) 0x81,
            (byte) 0x37, (byte) 0x83, (byte) 0x4f, (byte) 0x91, (byte) 0x15, (byte) 0x9b, (byte) 0x4e,
            (byte) 0x0e, (byte) 0x5a, (byte) 0xa8, (byte) 0x18, (byte) 0x61, (byte) 0x9a, (byte) 0x91,
            (byte) 0x23, (byte) 0x9d, (byte) 0xf4, (byte) 0xd3, (byte) 0x67, (byte) 0x0e, (byte) 0xe3,
            (byte) 0x61, (byte) 0xb1, (byte) 0xdb, (byte) 0x57, (byte) 0x25, (byte) 0x68, (byte) 0x10,
            (byte) 0xab, (byte) 0xca, (byte) 0x5a, (byte) 0x33, (byte) 0xd4, (byte) 0x9c, (byte) 0xe2,
            (byte) 0x75, (byte) 0x2e, (byte) 0x7b, (byte) 0x7d, (byte) 0x62, (byte) 0xab, (byte) 0xb2,
            (byte) 0xef, (byte) 0x9a, (byte) 0x34, (byte) 0x86, (byte) 0x48, (byte) 0xbe, (byte) 0x70,
            (byte) 0xf3, (byte) 0x83, (byte) 0x60, (byte) 0x95, (byte) 0x3e, (byte) 0x3c, (byte) 0x01,
            (byte) 0xca, (byte) 0x95, (byte) 0x1a, (byte) 0xbf, (byte) 0xbf, (byte) 0xe6, (byte) 0xfc,
            (byte) 0xbc, (byte) 0x09, (byte) 0xf4, (byte) 0xff };
    byte[] exponentBytes = { (byte) 0x1d, (byte) 0xe6, (byte) 0xf1, (byte) 0x60, (byte) 0x19, (byte) 0x90,
            (byte) 0x8b, (byte) 0x4e, (byte) 0x0c, (byte) 0xb1, (byte) 0xaa, (byte) 0xff, (byte) 0xdd,
            (byte) 0x37, (byte) 0x8a, (byte) 0xf3, (byte) 0xc8, (byte) 0x2a, (byte) 0x5b, (byte) 0x31,
            (byte) 0x13, (byte) 0x09, (byte) 0xfc, (byte) 0xc6, (byte) 0x30, (byte) 0xea, (byte) 0xf6,
            (byte) 0xf3, (byte) 0x84, (byte) 0x5f, (byte) 0x4c, (byte) 0x08, (byte) 0x4c, (byte) 0x09,
            (byte) 0x43, (byte) 0xca, (byte) 0x23, (byte) 0x43, (byte) 0x2f, (byte) 0x14, (byte) 0xec,
            (byte) 0x65, (byte) 0x77, (byte) 0x70, (byte) 0x26, (byte) 0x18, (byte) 0x70, (byte) 0x28,
            (byte) 0x55, (byte) 0x7d, (byte) 0x20, (byte) 0x74, (byte) 0x07, (byte) 0x1b, (byte) 0x9f,
            (byte) 0xa3, (byte) 0x20, (byte) 0xed, (byte) 0x0b, (byte) 0xef, (byte) 0xb0, (byte) 0xb5,
            (byte) 0xeb, (byte) 0xcd, (byte) 0x2f, (byte) 0xcd, (byte) 0x4d, (byte) 0xde, (byte) 0x37,
            (byte) 0xe5, (byte) 0x86, (byte) 0x55, (byte) 0xf2, (byte) 0x34, (byte) 0xe7, (byte) 0xd9,
            (byte) 0xf7, (byte) 0xb3, (byte) 0x45, (byte) 0x2a, (byte) 0x92, (byte) 0x1b, (byte) 0x54,
            (byte) 0x49, (byte) 0x41, (byte) 0x81, (byte) 0xbd, (byte) 0xc0, (byte) 0x63, (byte) 0xd1,
            (byte) 0x86, (byte) 0x45, (byte) 0xe7, (byte) 0xe3, (byte) 0xb3, (byte) 0xf5, (byte) 0x77,
            (byte) 0x5f, (byte) 0x46, (byte) 0x93, (byte) 0x20, (byte) 0x19, (byte) 0x9a, (byte) 0x26,
            (byte) 0x9f, (byte) 0x48, (byte) 0x27, (byte) 0x4b, (byte) 0x93, (byte) 0xa7, (byte) 0x1c,
            (byte) 0xf2, (byte) 0x8a, (byte) 0x3b, (byte) 0xbe, (byte) 0x40, (byte) 0x85, (byte) 0x92,
            (byte) 0x8a, (byte) 0x3c, (byte) 0xfd, (byte) 0xeb, (byte) 0x18, (byte) 0x2e, (byte) 0x04,
            (byte) 0x69, (byte) 0xe5, (byte) 0xa1 };
    BigInteger exponent = new BigInteger(1, exponentBytes);
    BigInteger modulus = new BigInteger(1, modulusBytes);
    RSAPrivateKeySpec ks = new RSAPrivateKeySpec(modulus, exponent);
    KeyFactory kf = KeyFactory.getInstance("RSA");
    return (RSAPrivateKey) kf.generatePrivate(ks);
}