generate RSA Key Pair - Android java.security

Android examples for java.security:RSA

Description

generate RSA Key Pair

Demo Code


//package com.java2s;

import java.security.*;

public class Main {

    public static KeyPair generateRSAKeyPair(int keySize) {
        KeyPair ret = null;/*from   w  w  w  . j  a v  a 2s  .  c o  m*/

        try {
            KeyPairGenerator generator = KeyPairGenerator
                    .getInstance("RSA");

            generator.initialize(keySize);
            ret = generator.generateKeyPair();

        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }

        return ret;
    }
}

Related Tutorials