List of usage examples for java.security PrivateKey toString
public String toString()
From source file:com.aqnote.shared.cryptology.cert.util.KeyStoreFileUtil.java
/** * ?KeyStore???/* w w w . ja va 2s . c o m*/ * * @param alias * @param pfxPath * @param password * @return * @throws UnrecoverableKeyException * @throws KeyStoreException * @throws NoSuchAlgorithmException * @throws CertificateException * @throws IOException */ public static String readPrivateKeyStr(String alias, String pfxPath, String password) throws UnrecoverableKeyException, KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException { PrivateKey privateKey = readPrivateKey(alias, pfxPath, password); return privateKey.toString().replace(" ", ""); }
From source file:org.jasig.portal.security.provider.saml.SSLSecurityImpl.java
private void setSSLClientCredentials(PrivateKey pk, Certificate cert) throws KeyStoreException, NoSuchProviderException, NoSuchAlgorithmException, CertificateException, IOException { this.logger.info("Private key: [{}].", pk.toString()); this.logger.info("Certificate: [{}].", cert.toString()); KeyStore ks = KeyStore.getInstance("JKS", "SUN"); ks.load(null, null);//from w ww.j a va2s . c om Certificate[] certificates = new Certificate[1]; certificates[0] = cert; String keystorePass = UUID.randomUUID().toString(); ks.setKeyEntry("sp", pk, keystorePass.toCharArray(), certificates); this.keyStore = ks; this.keyStorePass = keystorePass; }
From source file:com.microsoft.aad.adal4j.MSCAPIAsymmetricKeyCredential.java
/** * Constructor to create credential with client id, private key and public * certificate.//from w w w . ja v a 2s . c om * * @param clientId * Identifier of the client requesting the token. * @param key * RSA private key to sign the assertion. * @param publicCertificate * Public certificate used for thumb print. */ private MSCAPIAsymmetricKeyCredential(final String clientId, final PrivateKey key, final X509Certificate publicCertificate) { int KeySize = 0; if (StringHelper.isBlank(clientId)) { throw new IllegalArgumentException("clientId is null or empty"); } if (key == null) { throw new NullPointerException("PrivateKey"); } this.clientId = clientId; this.key = key; // Begin Updates by Rob Reilly 5/19/2016 if (key instanceof RSAPrivateKey) { KeySize = ((RSAPrivateKey) key).getModulus().bitLength(); } else if (key instanceof PrivateKey) { String keyData = key.toString(); Pattern pattern = Pattern.compile("(.*size=)(\\d{4,})(\\sbits)"); Matcher matcher = pattern.matcher(keyData); matcher.find(); KeySize = Integer.parseInt(matcher.group(2)); } if (KeySize < MIN_KEYSIZE_IN_BITS) { throw new IllegalArgumentException("certificate key size must be at least " + MIN_KEYSIZE_IN_BITS); } // End Updates by Rob Reilly 5/19/2016 this.publicCertificate = publicCertificate; }