Example usage for android.security.keystore KeyProperties ENCRYPTION_PADDING_RSA_OAEP

List of usage examples for android.security.keystore KeyProperties ENCRYPTION_PADDING_RSA_OAEP

Introduction

In this page you can find the example usage for android.security.keystore KeyProperties ENCRYPTION_PADDING_RSA_OAEP.

Prototype

String ENCRYPTION_PADDING_RSA_OAEP

To view the source code for android.security.keystore KeyProperties ENCRYPTION_PADDING_RSA_OAEP.

Click Source Link

Document

RSA Optimal Asymmetric Encryption Padding (OAEP) scheme.

Usage

From source file:Main.java

@TargetApi(Build.VERSION_CODES.M)
private static void generateNewKey() {
    try {//from   w  w  w  .j a va 2s.c om
        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_RSA,
                KEY_PROVIDER);

        keyPairGenerator.initialize(new KeyGenParameterSpec.Builder(KEY_ALIAS, KeyProperties.PURPOSE_DECRYPT)
                .setDigests(KeyProperties.DIGEST_SHA256, KeyProperties.DIGEST_SHA512)
                .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_OAEP).build());
        keyPairGenerator.generateKeyPair();

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