public static PublicKey fromX509PEM(Reader reader) throws IOException { return fromX509PEM(PEMFormatUtil.readerToString(reader)); } }
/** * Public keys are encoded with the X509 public key spec. * * @param encodedPublic * @return */ public static PublicKey fromX509PEM(String encodedPublic) { return fromX509DER(PEMFormatUtil.getBodyBytes(encodedPublic, BEGIN_PUBLIC_KEY, END_PUBLIC_KEY)); }
public static String fromCertReqToString(MyPKCS10CertRequest certReq) { if (certReq == null) return null; return PEMFormatUtil.bytesToChunkedString(certReq.getEncoded()); }
/** * Writes the retrieved credentials to the specified output stream. * * @param os OutputStream to write to * @throws IOException * @throws GeneralSecurityException */ public void saveCredentials(OutputStream os) throws IOException, GeneralSecurityException { CertUtil.toPEM(certificateChain, os); // since we are putting the private key in the same file as the certs, we have to // add a new line. os.write('\n'); KeyUtil.toPKCS1PEM(keypair.getPrivate(), os); }
/** * Retrieves credentials from the MyProxy server. */ public void getCredentials() throws IOException, GeneralSecurityException { KeyPairGenerator keyGenerator = KeyPairGenerator.getInstance(keyAlg); keyGenerator.initialize(getKeySize()); this.keypair = keyGenerator.genKeyPair(); MyPKCS10CertRequest pkcs10 = CertUtil.createCertRequest(this.keypair, pkcs10SigAlgName, DN, pkcs10Provider); getCredentials(pkcs10.getEncoded()); }
/** * Create a certification request with the default distinguished name * * @param keypair * @return * @throws SignatureException * @throws NoSuchProviderException * @throws InvalidKeyException * @throws NoSuchAlgorithmException * @throws IOException */ public static MyPKCS10CertRequest createCertRequest(KeyPair keypair) throws SignatureException, NoSuchProviderException, InvalidKeyException, NoSuchAlgorithmException, IOException { return createCertRequest(keypair, DEFAULT_PKCS10_DISTINGUISHED_NAME); }
public static String toPEM(Collection<X509Certificate> x509Certificates) { X509Certificate[] certs = new X509Certificate[x509Certificates.size()]; certs = x509Certificates.toArray(certs); return toPEM(certs); }
public RSA gen_key(int keyLength, int exponent, Object callback) throws NoSuchProviderException, NoSuchAlgorithmException { RSA rsa = new RSA(); keyPair = KeyUtil.generateKeyPair(); return rsa; } public void save_key(String fullPath, String cipher, Object callback) throws IOException {
public static PrivateKey fromPKCS8PEM(Reader reader) throws IOException { return fromPKCS8PEM(PEMFormatUtil.readerToString(reader)); }
public static String delimitBody(byte[] body, String head, String tail) { return delimitBody(bytesToChunkedString(body), head, tail); }
public static void toPKCS8PEM(PrivateKey privateKey, Writer writer) throws IOException { writer.write(toPKCS8PEM(privateKey)); writer.flush(); }
/** * This takes the PEM encoding of a PKCS 8 format private key, strips the header and footer, converts * to bytes then invokes {@link #fromPKCS8DER(byte[])}. * You can get a PKCS #8 private key that is PEM encoded from open ssl e.g. with * <code> * openssl pkcs8 -topk8 -nocrypt -in privkey.pem -inform PEM -out privkey-pkcs8.pem -outform PEM * </code><br><br> * * @param pem * @return * @throws edu.uiuc.ncsa.security.core.exceptions.GeneralException * */ public static PrivateKey fromPKCS8PEM(String pem) throws GeneralException { return fromPKCS8DER(PEMFormatUtil.getBodyBytes(pem, BEGIN_PRIVATE_KEY, END_PRIVATE_KEY)); }
/** * Gets the trusted CA certificates returned by the MyProxy server. * * @return trusted CA certificates, or null if none available */ public X509Certificate[] getTrustedCAs() throws CertificateException { if (trustrootData == null) return null; return CertUtil.getX509CertsFromStringList(trustrootData, trustrootFilenames); }
public static KeyPairGenerator getKeyPairGenerator() throws NoSuchProviderException, NoSuchAlgorithmException { if (keyPairGenerator == null) { keyPairGenerator = KeyPairGenerator.getInstance(getKeyAlgorithm()); keyPairGenerator.initialize(getKeyLength()); } return keyPairGenerator; }
public KeyPair getKeyPair() { return kpq.pop(); }
/** * Equivalent to <code>toString</code>.Returns the base 64 encoded string itself. * @return */ public String getValue(){ return toString(); } }
/** * Take a string that is an base64-encoded, DER-encoded PKCS10 certificate request,. This is, for instance * stored in a database and not PEM format. */ public static MyPKCS10CertRequest fromStringToCertReq(String x) { return new MySunPKCS_CR(Base64.decodeBase64(x)); }
/** * Create a certification request with a supplied distinguished name. This should be exactly * what you want it to be, e.g. the username. * * @param keypair * @param dn * @return * @throws SignatureException * @throws NoSuchProviderException * @throws InvalidKeyException * @throws NoSuchAlgorithmException * @throws IOException */ public static MyPKCS10CertRequest createCertRequest(KeyPair keypair, String dn) throws SignatureException, NoSuchProviderException, InvalidKeyException, NoSuchAlgorithmException, IOException { return createCertRequest(keypair, DEFAULT_PKCS10_SIGNATURE_ALGORITHM, dn, DEFAULT_PKCS10_PROVIDER); }
public static void delimitBody(byte[] body, String head, String tail, OutputStream outputStream) { delimitBody(bytesToChunkedString(body), head, tail, outputStream); }
/** * Take a private key and put it into PKCS 1 format. These are used, e.g., by OpenSSL. * * @return * @throws IOException */ public static String toPKCS1PEM(PrivateKey privateKey) throws IOException { byte[] bytes = privateKey.getEncoded(); return PEMFormatUtil.delimitBody(PEMFormatUtil.bytesToChunkedString(bytes), BEGIN_RSA_PRIVATE_KEY, END_RSA_PRIVATE_KEY); }