public static void delimitBody(byte[] body, String head, String tail, OutputStream outputStream) { delimitBody(bytesToChunkedString(body), head, tail, outputStream); }
public static byte[] getBodyBytes(String pem, String head, String tail) { return Base64.decodeBase64(getBody(pem, head, tail)); }
public static String fromCertReqToString(MyPKCS10CertRequest certReq) { if (certReq == null) return null; return PEMFormatUtil.bytesToChunkedString(certReq.getEncoded()); }
public static String toPKCS8PEM(PrivateKey privateKey) { return PEMFormatUtil.delimitBody(privateKey.getEncoded(), BEGIN_PRIVATE_KEY, END_PRIVATE_KEY); }
/** * 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 PublicKey fromX509PEM(Reader reader) throws IOException { return fromX509PEM(PEMFormatUtil.readerToString(reader)); } }
super.preGetCert(asset, parameters); OA2Asset a = (OA2Asset) asset; parameters.put(ClientEnvironment.CERT_REQUEST_KEY, PEMFormatUtil.bytesToChunkedString(asset.getCertReq().getEncoded())); if (!parameters.containsKey(getEnvironment().getConstants().get(CALLBACK_URI_KEY))) { parameters.put(getEnvironment().getConstants().get(CALLBACK_URI_KEY), getEnvironment().getCallback().toString());
public static void delimitBody(String body, String head, String tail, Writer writer) { delimitBody(body, head, tail, new PrintWriter(writer)); }
/** * 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)); }
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); }
/** * Take an X509 cert and encode it correctly in PEM format, writing the result to the * output stream. This will check for a known condition in various security suites (e.g. Open SSL) * in which an extra line feed will cause the entire result to be rejected. This extra line feed * occurs in the odd case that the encoded cert's length is a multiple of the line length. The only * way to catch this is to encode it as a string, then check if the last character is a line feed. * * @param x509Certificate * @param outputStream * @throws java.security.cert.CertificateEncodingException */ public static void toPEM(X509Certificate x509Certificate, OutputStream outputStream) throws CertificateEncodingException { PEMFormatUtil.delimitBody(x509Certificate.getEncoded(), BEGIN_CERTIFICATE, END_CERTIFICATE, 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); }
public static void delimitBody(String body, String head, String tail, OutputStream outputStream) { delimitBody(body, head, tail, new PrintWriter(outputStream)); }
public static String toX509PEM(PublicKey publicKey) { byte[] bytes = publicKey.getEncoded(); return PEMFormatUtil.delimitBody(PEMFormatUtil.bytesToChunkedString(bytes), BEGIN_PUBLIC_KEY, END_PUBLIC_KEY); }
/** * Utility to delimit a string (usually base 4 encoded DER byte array) with specific * head and tail. This checks that there are not extra carriage returns (which would invalidate * the output). * * @param body * @param head * @param tail * @return */ public static String delimitBody(String body, String head, String tail) { StringWriter sw = new StringWriter(); delimitBody(body, head, tail, sw); return sw.getBuffer().toString(); }