Android Hash Code Calculate hash(char[] pin, byte[] salt)

Here you can find the source of hash(char[] pin, byte[] salt)

Description

hash

Declaration

private static byte[] hash(char[] pin, byte[] salt)
            throws NoSuchAlgorithmException, InvalidKeySpecException 

Method Source Code

//package com.java2s;

import java.security.NoSuchAlgorithmException;

import java.security.spec.InvalidKeySpecException;
import java.util.Arrays;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;

public class Main {
    private static final int ROUNDS = 100;
    private static final int KEY_LEN = 256;
    private static final String KEY_ALGORITHM = "PBKDF2WithHmacSHA1";

    private static byte[] hash(char[] pin, byte[] salt)
            throws NoSuchAlgorithmException, InvalidKeySpecException {
        PBEKeySpec spec = new PBEKeySpec(pin, salt, ROUNDS, KEY_LEN);
        Arrays.fill(pin, Character.MIN_VALUE);
        try {//from   w  w  w.  j  a  v  a  2 s.  c  om
            SecretKeyFactory skf = SecretKeyFactory
                    .getInstance(KEY_ALGORITHM);
            return skf.generateSecret(spec).getEncoded();
        } finally {
            spec.clearPassword();
        }
    }
}

Related

  1. hash(File file, String algorithm)
  2. hash(String input, String algorithm)
  3. hash(String password)
  4. hash(String s, String algorithm)
  5. hash(int seed, Object o)
  6. hash(int seed, boolean x)
  7. hash(int seed, int x)
  8. hash2jsonBytes(Map hash)