RSA encrypt Data with Public key - Android java.security

Android examples for java.security:RSA

Description

RSA encrypt Data with Public key

Demo Code


//package com.java2s;

import java.security.PublicKey;

import javax.crypto.Cipher;

public class Main {
    private static String RSA = "RSA";

    public static byte[] encryptData(byte[] data, PublicKey publicKey) {
        try {/*from  w  w  w  .j  a v a2 s  .co  m*/
            Cipher cipher = Cipher.getInstance(RSA);

            cipher.init(Cipher.ENCRYPT_MODE, publicKey);

            return cipher.doFinal(data);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}

Related Tutorials