verify RSA Digital Signature - Android java.security

Android examples for java.security:RSA

Description

verify RSA Digital Signature

Demo Code


//package com.java2s;

import android.util.Base64;
import java.security.InvalidKeyException;

import java.security.NoSuchAlgorithmException;

import java.security.PublicKey;

import java.security.Signature;
import java.security.SignatureException;

public class Main {
    public static boolean verifyDigitalSignature(String payload,
            String signedPayload, PublicKey publicKey)
            throws NoSuchAlgorithmException, InvalidKeyException,
            SignatureException {/*ww  w.ja v  a2 s  .  c om*/
        Signature signature = Signature.getInstance("SHA256withRSA");
        signature.initVerify(publicKey);
        signature.update(payload.getBytes());

        byte[] signedPayloadContent = Base64.decode(signedPayload,
                Base64.DEFAULT);

        return signature.verify(signedPayloadContent);
    }
}

Related Tutorials