create PBE Key - Java Security

Java examples for Security:Key

Description

create PBE Key

Demo Code


//package com.java2s;
import javax.crypto.*;

import javax.crypto.spec.PBEKeySpec;

import java.security.Key;

public class Main {
    public static Key createPBEKey(char[] password, byte[] salt,
            int iterationCount, String algorithm, String provider)
            throws Exception {
        PBEKeySpec pbeSpec = new PBEKeySpec(password, salt, iterationCount);
        SecretKeyFactory keyFact = SecretKeyFactory.getInstance(algorithm,
                provider);/*from  ww  w.  ja va2 s.com*/
        Key sKey = keyFact.generateSecret(pbeSpec);
        return sKey;
    }
}

Related Tutorials