private static String encryptCodeGrant( ServerAuthorizationCodeGrant grant, Key secretKey, KeyProperties props) throws SecurityException { String tokenSequence = tokenizeCodeGrant(grant); return CryptoUtils.encryptSequence(tokenSequence, secretKey, props); }
@Test public void testWriteReadJwsSignedByESPrivateKey() throws Exception { JwtHeaders headers = new JwtHeaders(); headers.setAlgorithm(Algorithm.SHA256withECDSA.getJwtName()); JwsCompactProducer jws = initSpecJwtTokenWriter(headers); ECPrivateKey privateKey = CryptoUtils.getECPrivateKey(EC_PRIVATE_KEY_ENCODED); jws.signWith(new EcDsaJwsSignatureProvider(privateKey)); String signedJws = jws.getSignedEncodedJws(); ECPublicKey publicKey = CryptoUtils.getECPublicKey(EC_X_POINT_ENCODED, EC_Y_POINT_ENCODED); JwsJwtCompactConsumer jwsConsumer = new JwsJwtCompactConsumer(signedJws); assertTrue(jwsConsumer.verifySignatureWith(new PublicKeyJwsSignatureVerifier(publicKey))); JwtToken token = jwsConsumer.getJwtToken(); JwtHeaders headersReceived = token.getHeaders(); assertEquals(Algorithm.SHA256withECDSA.getJwtName(), headersReceived.getAlgorithm()); validateSpecClaim(token.getClaims()); }
public SecretKey decodeSecretKey(String encodedSecretKey, String secretKeyAlgorithm) { String secretKeyAlgorithmToUse = secretKeyAlgorithm; if (!Strings.isValid(secretKeyAlgorithmToUse)) { secretKeyAlgorithmToUse = AES_CRYPTO_ALGO; } return CryptoUtils.decodeSecretKey(encodedSecretKey, secretKeyAlgorithmToUse); }
@Test public void testReadJwsSignedByPrivateKey() throws Exception { JwsJwtCompactConsumer jws = new JwsJwtCompactConsumer(ENCODED_TOKEN_SIGNED_BY_PRIVATE_KEY); RSAPublicKey key = CryptoUtils.getRSAPublicKey(RSA_MODULUS_ENCODED, RSA_PUBLIC_EXPONENT_ENCODED); assertTrue(jws.verifySignatureWith(new PublicKeyJwsSignatureVerifier(key))); JwtToken token = jws.getJwtToken(); JwtHeaders headers = token.getHeaders(); assertEquals(Algorithm.SHA256withRSA.getJwtName(), headers.getAlgorithm()); validateSpecClaim(token.getClaims()); }
@Test public void testWriteJwsSignedByPrivateKey() throws Exception { JwtHeaders headers = new JwtHeaders(); headers.setAlgorithm(Algorithm.SHA256withRSA.getJwtName()); JwsCompactProducer jws = initSpecJwtTokenWriter(headers); PrivateKey key = CryptoUtils.getRSAPrivateKey(RSA_MODULUS_ENCODED, RSA_PRIVATE_EXPONENT_ENCODED); jws.signWith(new PrivateKeyJwsSignatureProvider(key)); assertEquals(ENCODED_TOKEN_SIGNED_BY_PRIVATE_KEY, jws.getSignedEncodedJws()); }
public AesWrapKeyDecryptionAlgorithm(byte[] secretKey) { this(CryptoUtils.createSecretKeySpec(secretKey, Algorithm.AES_WRAP_ALGO_JAVA)); }
public AesWrapKeyDecryptionAlgorithm(String encodedKey) { this(CryptoUtils.decodeSequence(encodedKey)); }
private static String encryptAccessToken( ServerAccessToken token, Key secretKey, KeyProperties props) throws SecurityException { String tokenSequence = tokenizeServerToken(token); return CryptoUtils.encryptSequence(tokenSequence, secretKey, props); }
private static RefreshToken decryptRefreshToken( OAuthDataProvider provider, String encodedData, Key key, KeyProperties props) throws SecurityException { String decryptedSequence = CryptoUtils.decryptSequence(encodedData, key, props); return recreateRefreshToken(provider, encodedData, decryptedSequence); }
private static ServerAccessToken decryptAccessToken( OAuthDataProvider provider, String encodedData, Key secretKey, KeyProperties props) throws SecurityException { String decryptedSequence = CryptoUtils.decryptSequence(encodedData, secretKey, props); return recreateAccessToken(provider, encodedData, decryptedSequence); }
private static ServerAuthorizationCodeGrant decryptCodeGrant( OAuthDataProvider provider, String encodedData, Key key, KeyProperties props) throws SecurityException { String decryptedSequence = CryptoUtils.decryptSequence(encodedData, key, props); return recreateCodeGrant(provider, decryptedSequence); }