Java Code Examples for com.nimbusds.jose.EncryptionMethod#A128GCM
The following examples show how to use
com.nimbusds.jose.EncryptionMethod#A128GCM .
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: JweTokenSerializer.java From OAuth-2.0-Cookbook with MIT License | 6 votes |
public String encode(String payload) { JWEAlgorithm alg = JWEAlgorithm.A128KW; EncryptionMethod encryptionMethod = EncryptionMethod.A128GCM; try { byte[] decodedKey = Base64.getDecoder().decode(encodedKeypair); SecretKey key = new SecretKeySpec(decodedKey, 0, decodedKey.length, "AES"); JWEObject jwe = new JWEObject( new JWEHeader(alg, encryptionMethod), new Payload(payload)); jwe.encrypt(new AESEncrypter(key)); return jwe.serialize(); } catch (Exception e) { throw new RuntimeException(e); } }
Example 2
Source File: JweTokenSerializer.java From OAuth-2.0-Cookbook with MIT License | 6 votes |
public String encode(String payload) { JWEAlgorithm alg = JWEAlgorithm.A128KW; EncryptionMethod encryptionMethod = EncryptionMethod.A128GCM; try { byte[] decodedKey = Base64.getDecoder().decode(encodedKeypair); SecretKey key = new SecretKeySpec(decodedKey, 0, decodedKey.length, "AES"); JWEObject jwe = new JWEObject( new JWEHeader(alg, encryptionMethod), new Payload(payload)); jwe.encrypt(new AESEncrypter(key)); return jwe.serialize(); } catch (Exception e) { throw new RuntimeException(e); } }
Example 3
Source File: EncryptionUtility.java From amex-api-java-client-core with Apache License 2.0 | 6 votes |
public String encrypt(String data, String keyId, String aesKey) { try { byte[] keyBytes = Base64.decode(aesKey); SecretKeySpec secretKey = new SecretKeySpec(keyBytes, 0, keyBytes.length, "AES"); JWEAlgorithm jweAlgorithm = JWEAlgorithm.A256KW; EncryptionMethod encryptionMethod = EncryptionMethod.A128GCM; JWEHeader.Builder headerBuilder = new JWEHeader.Builder(jweAlgorithm, encryptionMethod); headerBuilder.keyID(keyId); JWEHeader header = headerBuilder.build(); JWEEncrypter encrypter = new AESEncrypter(secretKey); encrypter.getJCAContext().setProvider(BouncyCastleProviderSingleton.getInstance()); JWEObject jweObject = new JWEObject(header, new Payload(data)); jweObject.encrypt(encrypter); return jweObject.serialize(); } catch (Exception e) { throw new CryptoException("Exception encrypting data: " + e.getMessage(), e); } }