output RSA Key - Android java.security

Android examples for java.security:RSA

Description

output RSA Key

Demo Code


//package com.java2s;

import android.util.Base64;

import java.security.*;

import java.util.ArrayList;
import java.util.List;

public class Main {

    public static List<String> outputRSAKey(PrivateKey privateKey,
            PublicKey publicKey) {
        List<String> list = null;
        if (privateKey != null && publicKey != null) {
            list = new ArrayList<>();
            byte[] privateKeyEncoded = privateKey.getEncoded();
            String privateStr = Base64.encodeToString(privateKeyEncoded,
                    Base64.NO_WRAP);// w  w w  .  j a va  2s  . com
            byte[] publicKeyEncoded = publicKey.getEncoded();
            String publicStr = Base64.encodeToString(publicKeyEncoded,
                    Base64.NO_WRAP);
            list.add(privateStr);
            list.add(publicStr);
        }
        return list;
    }
}

Related Tutorials