use of org.ballerinalang.nativeimpl.jwt.crypto.RSAVerifier in project ballerina by ballerina-lang.
the class JWTVerifierTest method testRSA256Verifier.
@Test(description = "Test RSAVerifier with SHA-256 hashing ")
public void testRSA256Verifier() throws Exception {
String data = "ewogICJhbGciOiAiUlMyNTYiLAogICJ0eXAiOiAiSldUIgp9.ewogICJzdWIiOiAiMTIzNjU0IiwKICAibmFtZSI6ICJK" + "b2huIiwKICAiaXNzIjogIndzbzIiLAogICJhdWQiOiAiYmFsbGVyaW5hIiwKICAiZXhwIjogMTUxOTk5NDU2NDI0OQp9";
String signature = "X10zu93zSfo0TJQdyDrWZEr5RfX-8vA3dNuxkVRhhj_v51Q7FQ2WUP_rQpJGL2VyFpu23W1ypXXGiDMqDZodqQ8v" + "cf1ElO_qIC6ls0Ay6fHzjpLQdVU7bkFfpuqoboXfOSLCxwzHnvKNIWqmVBHW7CE4jPjb7_11QpT1CxwIUSXtVFk2" + "Z3gpCyfwCVe_JXtBwDbyCQGO_g2tKUSwHvvNDu3THgCcB2ALIS_JznaK9iPf55YmeNwB_KRGkaY-VLvQ5iUILWp2" + "J5SF3QavfXMNhv8GoEDBe2ZfbQgH5E-TpakoL51Ix8vELiznVl7sbtAqlD97440hW3wXoq68kboCVQ==";
String algorithm = "RS256";
RSAPublicKey publicKey = getRSAPublicKey();
JWSVerifier verifier = new RSAVerifier(publicKey);
Assert.assertTrue(verifier.verify(data, signature, algorithm));
}
use of org.ballerinalang.nativeimpl.jwt.crypto.RSAVerifier in project ballerina by ballerina-lang.
the class Verify method execute.
@Override
public void execute(Context context) {
String data = context.getStringArgument(0);
String signature = context.getStringArgument(1);
String algorithm = context.getStringArgument(2);
String keyAlias = context.getStringArgument(3);
Boolean validSignature = null;
RSAPublicKey publicKey;
try {
publicKey = (RSAPublicKey) KeyStore.getKeyStore().getTrustedPublicKey(keyAlias);
JWSVerifier verifier = new RSAVerifier(publicKey);
validSignature = verifier.verify(data, signature, algorithm);
context.setReturnValues(new BBoolean(validSignature));
} catch (Exception e) {
context.setReturnValues(new BBoolean(false), BLangVMErrors.createError(context, 0, e.getMessage()));
}
}
Aggregations