generate Asymmetric Key Pair - Android java.security

Android examples for java.security:Key

Description

generate Asymmetric Key Pair

Demo Code


//package com.java2s;

import java.security.KeyPair;
import java.security.KeyPairGenerator;

import java.security.NoSuchAlgorithmException;

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

    public static KeyPair generateAsymmetricKeyPair(int keySize) {
        KeyPairGenerator kgen;//  w  w w  . ja  va  2  s  .c om
        try {
            kgen = KeyPairGenerator.getInstance(ASYMMETRIC_ALGORITHM);
            kgen.initialize(keySize);
            return kgen.generateKeyPair();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related Tutorials