use of java.security.interfaces.RSAPrivateKey in project cxf by apache.
the class JweCompactReaderWriterTest method decrypt.
private void decrypt(String jweContent, String plainContent, boolean unwrap) throws Exception {
RSAPrivateKey privateKey = CryptoUtils.getRSAPrivateKey(RSA_MODULUS_ENCODED_A1, RSA_PRIVATE_EXPONENT_ENCODED_A1);
ContentAlgorithm algo = Cipher.getMaxAllowedKeyLength("AES") > 128 ? ContentAlgorithm.A256GCM : ContentAlgorithm.A128GCM;
JweDecryptionProvider decryptor = new JweDecryption(new RSAKeyDecryptionAlgorithm(privateKey), new AesGcmContentDecryptionAlgorithm(algo));
String decryptedText = decryptor.decrypt(jweContent).getContentText();
assertEquals(decryptedText, plainContent);
}
use of java.security.interfaces.RSAPrivateKey in project carbon-apimgt by wso2.
the class JWTWithRSASignatureImplTestCase method testRSASignAndSerializeWithNullJWTClaimsSet.
@Test(description = "Test RSA sign and serialize when JWT Claims Set is null", expectedExceptions = IllegalArgumentException.class)
public void testRSASignAndSerializeWithNullJWTClaimsSet() throws APIManagementException {
JWTWithRSASignatureImpl jwtWithRSASignature = new JWTWithRSASignatureImpl();
RSAPrivateKey rsaPrivateKey = Mockito.mock(RSAPrivateKey.class);
jwtWithRSASignature.rsaSignAndSerialize(rsaPrivateKey, null);
}
use of java.security.interfaces.RSAPrivateKey in project baseio by generallycloud.
the class RSAUtil method generateKeys.
public static void generateKeys(String file, int length) throws NoSuchAlgorithmException, IOException {
RSAKeys keys = RSAUtil.getKeys(length);
// 生成公钥和私钥
RSAPublicKey publicKey = keys.getPublicKey();
RSAPrivateKey privateKey = keys.getPrivateKey();
File publicKeyFile = new File(file + "/public.rsa");
String publicKeyString = publicKey.toString();
File privateKeyFile = new File(file + "/private.rsa");
String privateKeyString = privateKey.toString();
FileUtil.writeByFile(publicKeyFile, publicKeyString);
FileUtil.writeByFile(privateKeyFile, privateKeyString);
System.out.println("Public RSA File:" + publicKeyFile.getCanonicalPath());
System.out.println(publicKeyString);
System.out.println();
System.out.println("Private RSA File:" + privateKeyFile.getCanonicalPath());
System.out.println(privateKeyString);
}
Aggregations