RSA decrypt byte array with key - Android java.security

Android examples for java.security:RSA

Description

RSA decrypt byte array with key

Demo Code


//package com.java2s;

import android.util.Log;

import java.security.Key;

import javax.crypto.Cipher;

public class Main {
    public static byte[] decrypt(Key privateKey, byte[] encryptedText) {
        try {//www.jav a2 s. c  o m
            Cipher rsaCipher = Cipher.getInstance(
                    "RSA/ECB/OAEPWithSHA1AndMGF1Padding", "BC");
            rsaCipher.init(Cipher.DECRYPT_MODE, privateKey);
            return rsaCipher.doFinal(encryptedText);
        } catch (Exception e) {
            Log.e("RSAHelper",
                    "Error while decrypting data: " + e.getMessage());
            throw new RuntimeException(e);
        }
    }
}

Related Tutorials