Esempio n. 1
0
  private static String encryptCodeGrant(
      ServerAuthorizationCodeGrant grant, Key secretKey, KeyProperties props)
      throws SecurityException {
    String tokenSequence = tokenizeCodeGrant(grant);

    return CryptoUtils.encryptSequence(tokenSequence, secretKey, props);
  }
Esempio n. 2
0
 @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());
 }
Esempio n. 3
0
 public SecretKey decodeSecretKey(String encodedSecretKey, String secretKeyAlgorithm) {
   String secretKeyAlgorithmToUse = secretKeyAlgorithm;
   if (!Strings.isValid(secretKeyAlgorithmToUse)) {
     secretKeyAlgorithmToUse = AES_CRYPTO_ALGO;
   }
   return CryptoUtils.decodeSecretKey(encodedSecretKey, secretKeyAlgorithmToUse);
 }
Esempio n. 4
0
 @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());
 }
Esempio n. 5
0
  @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));
 }
Esempio n. 8
0
 private static String encryptAccessToken(
     ServerAccessToken token, Key secretKey, KeyProperties props) throws SecurityException {
   String tokenSequence = tokenizeServerToken(token);
   return CryptoUtils.encryptSequence(tokenSequence, secretKey, props);
 }
Esempio n. 9
0
 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);
 }
Esempio n. 10
0
 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);
 }
Esempio n. 11
0
 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);
 }