-
Notifications
You must be signed in to change notification settings - Fork 0
/
EncodeDecode.java
33 lines (28 loc) · 1.29 KB
/
EncodeDecode.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.math.BigInteger;
class EncodeDecode {
public static void main(String args[]){
}
public static String decryptJWEJWTString(String encryptedString, String identifier) {
JWT jwtReader = null;
try{
jwtReader = JWTParser.parse(encryptedString);
if (jwtReader instanceof PlainJWT) {
JSONObject payload = new JSONObject(((PlainJWT) jwtReader).getPayload().toString());
return payload.getString("id");
} else if(jwtReader instanceof EncryptedJWT){
JWEObject jweObject = JWEObject.parse(encryptedString);
jweObject.decrypt(new KeyMakerJWEDecrypter());
Payload plainData = jweObject.getPayload();
if(ApplicationConstants.CARD.equalsIgnoreCase(identifier)){
return String.valueOf(new BigInteger(1, plainData.toBytes()));
}
return plainData.toString();
}
} catch(Exception e){
logger.error("JWT/JWE Decryption failed. " + encryptedString);
CalEventFactory.create("Decryption JWT/JWE String", "Decryption failed ", "1",
" encrypted String : " + encryptedString + " Exception : "+ e.getMessage()).completed();
}
return null;
}
}