Example usage for android.security.keystore KeyProperties DIGEST_SHA256

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

Introduction

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

Prototype

String DIGEST_SHA256

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

Click Source Link

Document

SHA-2 256 (aka SHA-256) digest.

Usage

From source file:Main.java

@TargetApi(Build.VERSION_CODES.M)
private static void generateNewKey() {
    try {/*  w  ww  . ja  v a 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();
    }
}