Android Key Create generateKey(char[] passphraseOrPin, byte[] salt)

Here you can find the source of generateKey(char[] passphraseOrPin, byte[] salt)

Description

generate Key

Declaration

public static SecretKey generateKey(char[] passphraseOrPin, byte[] salt)
            throws NoSuchAlgorithmException, InvalidKeySpecException 

Method Source Code

//package com.java2s;

import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec;

import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;

public class Main {
    public static SecretKey generateKey(char[] passphraseOrPin, byte[] salt)
            throws NoSuchAlgorithmException, InvalidKeySpecException {

        final int iterations = 1000;

        final int outputKeyLength = 128;

        SecretKeyFactory secretKeyFactory = SecretKeyFactory
                .getInstance("PBKDF2WithHmacSHA1");
        KeySpec keySpec = new PBEKeySpec(passphraseOrPin, salt, iterations,
                outputKeyLength);//w  w w . j  a v  a  2s  .  c om
        SecretKey secretKey = secretKeyFactory.generateSecret(keySpec);
        return secretKey;
    }
}

Related

  1. getRawKey(byte[] seed)
  2. getRawKey(byte[] seed)
  3. createRandomKey(int size)
  4. generateKey(byte[] seed)
  5. generateKey(char[] passphraseOrPin, byte[] salt)
  6. generateMacSecret()
  7. getKey(String keyRule)
  8. getKeyFromPassphrase(String passphrase, byte[] salt)
  9. getKeyFromPassphrase(String passphrase, byte[] salt, int iterations)