use of com.nimbusds.jose.JWEEncrypter in project fitpay-android-sdk by fitpay.
the class StringUtils method getEncryptedString.
/**
* Get encrypted string
*
* @param type key type
* @param decryptedString decrypted string
* @return encrypted string
*/
public static String getEncryptedString(@KeysManager.KeyType int type, String decryptedString) {
JWEAlgorithm alg = JWEAlgorithm.A256GCMKW;
EncryptionMethod enc = EncryptionMethod.A256GCM;
ECCKeyPair keyPair = KeysManager.getInstance().getPairForType(type);
if (null == keyPair) {
throw new IllegalStateException("No key pair available for type (type = " + type + ")");
}
JWEHeader.Builder jweHeaderBuilder = new JWEHeader.Builder(alg, enc).contentType("application/json").keyID(keyPair.getKeyId());
JWEHeader header = jweHeaderBuilder.build();
Payload payload = new Payload(decryptedString);
JWEObject jweObject = new JWEObject(header, payload);
try {
JWEEncrypter encrypter = new AESEncrypter(KeysManager.getInstance().getSecretKey(type));
jweObject.encrypt(encrypter);
} catch (JOSEException e) {
FPLog.e(e);
}
return jweObject.serialize();
}
Aggregations