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);/*from w  w w.j a v a 2s. co m*/
        return secretKeyFactory.generateSecret(keySpec);
    }
}

Related

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