Search in sources :

Example 11 with X509Certificate

use of com.itrus.cert.X509Certificate in project spring-cloud-digital-sign by SpringForAll.

the class ServerPKCSUtil method genP12.

/**
 * @param password
 *            产生私钥证书的密码
 * @param certSignBuf
 *            公钥证书
 *
 * @return Base64的私钥证书
 */
public static String genP12(String password, String certSignBuf) {
    // 当前userId 不存在keyMap时抛出异常
    KeyStore ks = null;
    X509Certificate cert = null;
    ByteArrayOutputStream out = null;
    try {
        ks = KeyStore.getInstance("PKCS12");
        ks.load(null, password.toCharArray());
        cert = X509Certificate.getInstance(certSignBuf);
        String alias = cert.getSerialNumber().toString(16).toUpperCase();
        Certificate[] certChain = new Certificate[] { cert };
        KeyPair kp = securityKP;
        out = new ByteArrayOutputStream();
        ks.setKeyEntry(alias, kp.getPrivate(), password.toCharArray(), certChain);
        ks.store(out, password.toCharArray());
    } catch (KeyStoreException e) {
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (CertificateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return new String(Base64.encode(out.toByteArray()));
}
Also used : KeyPair(java.security.KeyPair) CertificateException(java.security.cert.CertificateException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) KeyStoreException(java.security.KeyStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) KeyStore(java.security.KeyStore) X509Certificate(com.itrus.cert.X509Certificate) Certificate(java.security.cert.Certificate) X509Certificate(com.itrus.cert.X509Certificate)

Aggregations

X509Certificate (com.itrus.cert.X509Certificate)11 CertificateException (java.security.cert.CertificateException)10 IOException (java.io.IOException)6 CRLException (java.security.cert.CRLException)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 SigningServerException (com.itrus.cryptorole.SigningServerException)3 CrlContext (com.itrus.portal.db.CrlContext)3 NoSuchProviderException (java.security.NoSuchProviderException)3 SignatureException (java.security.SignatureException)3 UserInfoServiceException (com.itrus.portal.exception.UserInfoServiceException)2 FileNotFoundException (java.io.FileNotFoundException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 KeyStoreException (java.security.KeyStoreException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 ParseException (java.text.ParseException)2 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)2 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)2 CryptoException (com.itrus.cryptorole.CryptoException)1 NotSupportException (com.itrus.cryptorole.NotSupportException)1 ItrusCRL (com.itrus.portal.certAPI.cert.ItrusCRL)1