use of org.owasp.oag.exception.ConsistencyException in project Application-Gateway by gianlucafrei.
the class JwtSigner method createSignedJwt.
/**
* Creates the JWT and adds the passed in claims and signs it.
* this is a template method.
*
* @param claimsSet the claims to add to the JWT
* @return The signed JWT in Base64 encoded format.
*/
public String createSignedJwt(JWTClaimsSet claimsSet) {
JWSHeader jwsHeader = createJwsHeader();
SignedJWT signedJWT = new SignedJWT(jwsHeader, claimsSet);
try {
signedJWT.sign(getJwtSigner());
} catch (JOSEException e) {
throw new ConsistencyException("Could not sign jwt", e);
}
String jwt = signedJWT.serialize();
return jwt;
}
use of org.owasp.oag.exception.ConsistencyException in project Application-Gateway by gianlucafrei.
the class JweEncrypter method loadFromFileOrCreateAndStoreNewKey.
public static JweEncrypter loadFromFileOrCreateAndStoreNewKey(String filename) throws IOException {
if (filename == null)
throw new ApplicationException("Filename must not be null", null);
File keyFile = new File(filename);
byte[] keyBytes;
if (keyFile.exists()) {
// Read key from file
keyBytes = Files.toByteArray(keyFile);
} else {
// Create new secret key and store it in file
KeyGenerator keyGen;
try {
keyGen = KeyGenerator.getInstance("AES");
// for example
keyGen.init(128);
SecretKey secretKey = keyGen.generateKey();
// Store key om file
keyBytes = secretKey.getEncoded();
Files.write(keyBytes, keyFile);
} catch (NoSuchAlgorithmException e) {
throw new ConsistencyException("Cloud not create AES key", e);
}
}
return new JweEncrypter(keyBytes);
}
use of org.owasp.oag.exception.ConsistencyException in project Application-Gateway by gianlucafrei.
the class JweEncrypter method encryptObject.
@Override
public String encryptObject(Object payload) {
try {
ObjectMapper objectMapper = new ObjectMapper();
String payloadString = objectMapper.writeValueAsString(payload);
return encrypt(payloadString);
} catch (JsonProcessingException e) {
throw new ConsistencyException("Could not encode Json", e);
}
}
Aggregations