com.alipay.api.internal.util.StreamUtil Java Examples

The following examples show how to use com.alipay.api.internal.util.StreamUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RSAEncryptor.java    From alipay-sdk-java-all with Apache License 2.0 5 votes vote down vote up
public static PrivateKey getPrivateKeyFromPKCS8(String algorithm,
                                                InputStream ins) throws Exception {
    if (ins == null || StringUtils.isEmpty(algorithm)) {
        return null;
    }

    KeyFactory keyFactory = KeyFactory.getInstance(algorithm);

    byte[] encodedKey = StreamUtil.readText(ins).getBytes();

    encodedKey = Base64.decodeBase64(encodedKey);

    return keyFactory.generatePrivate(new PKCS8EncodedKeySpec(encodedKey));
}
 
Example #2
Source File: RSAEncryptor.java    From alipay-sdk-java-all with Apache License 2.0 3 votes vote down vote up
public static PublicKey getPublicKeyFromX509(String algorithm,
                                             InputStream ins) throws Exception {
    KeyFactory keyFactory = KeyFactory.getInstance(algorithm);

    StringWriter writer = new StringWriter();
    StreamUtil.io(new InputStreamReader(ins), writer);

    byte[] encodedKey = writer.toString().getBytes();

    encodedKey = Base64.decodeBase64(encodedKey);

    return keyFactory.generatePublic(new X509EncodedKeySpec(encodedKey));
}