RSA decrypt Bytes with Key - Android java.security

Android examples for java.security:RSA

Description

RSA decrypt Bytes with Key

Demo Code


//package com.java2s;

import java.security.Key;

import javax.crypto.Cipher;

public class Main {
    public static String decryptBytes(Key key, byte[] bytes) {
        try {/*ww  w  .  ja v  a  2s. c o  m*/
            Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
            cipher.init(Cipher.DECRYPT_MODE, key);
            byte[] enBytes = cipher.doFinal(bytes);
            return new String(enBytes);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}

Related Tutorials