Search in sources :

Example 56 with RSAPrivateKey

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);
}
Also used : ContentAlgorithm(org.apache.cxf.rs.security.jose.jwa.ContentAlgorithm) RSAPrivateKey(java.security.interfaces.RSAPrivateKey)

Example 57 with RSAPrivateKey

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);
}
Also used : RSAPrivateKey(java.security.interfaces.RSAPrivateKey) Test(org.testng.annotations.Test)

Example 58 with RSAPrivateKey

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);
}
Also used : RSAPublicKey(java.security.interfaces.RSAPublicKey) RSAPrivateKey(java.security.interfaces.RSAPrivateKey) File(java.io.File)

Aggregations

RSAPrivateKey (java.security.interfaces.RSAPrivateKey)58 RSAPublicKey (java.security.interfaces.RSAPublicKey)29 KeyFactory (java.security.KeyFactory)15 InvalidKeyException (java.security.InvalidKeyException)14 PKCS8EncodedKeySpec (java.security.spec.PKCS8EncodedKeySpec)14 KeyPair (java.security.KeyPair)12 PrivateKey (java.security.PrivateKey)12 PublicKey (java.security.PublicKey)11 RSAPrivateCrtKey (java.security.interfaces.RSAPrivateCrtKey)11 RSAPrivateKeySpec (java.security.spec.RSAPrivateKeySpec)11 KeyPairGenerator (java.security.KeyPairGenerator)9 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)9 BigInteger (java.math.BigInteger)8 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)7 RSAPublicKeySpec (java.security.spec.RSAPublicKeySpec)7 IOException (java.io.IOException)6 Key (java.security.Key)5 RSAPrivateCrtKeySpec (java.security.spec.RSAPrivateCrtKeySpec)5 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)5 HashMap (java.util.HashMap)5