java.lang.Objectorg.pre4j.crypto.impl.PBESecretKey
public class PBESecretKey
A SecretKey for Password-Based Encryption (PBE) as defined in PKCS #5.
// Create PBE key
PBESecretKey key = new PBESecretKey(password, salt, count, "PBEWithMD5AndDES");
// Create PBE Cipher
Cipher cipher = Cipher.getInstance(key.getAlgorithm());
// Initialize PBE Cipher with key and parameters
cipher.init(Cipher.ENCRYPT_MODE, key, key.getParamSpec());
// Encrypt the cleartext
byte[] ciphertext = cipher.doFinal("This is an example".getBytes());
// Decrypt the ciphertext
cipher.init(Cipher.DECRYPT_MODE, key, key.getParamSpec());
byte[] plaintext = cipher.doFinal(ciphertext);
| Constructor Summary | |
|---|---|
PBESecretKey(char[] password)
Creates a new SecretKey based on the given password. |
|
PBESecretKey(char[] password,
java.lang.String algorithm,
byte[] salt,
int count)
Creates a new SecretKey based on the given password. |
|
| Method Summary | |
|---|---|
boolean |
equals(java.lang.Object obj)
|
java.lang.String |
getAlgorithm()
|
byte[] |
getEncoded()
|
java.lang.String |
getFormat()
|
javax.crypto.spec.PBEParameterSpec |
getParamSpec()
|
int |
hashCode()
|
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public PBESecretKey(char[] password)
public PBESecretKey(char[] password,
java.lang.String algorithm,
byte[] salt,
int count)
throws java.security.spec.InvalidKeySpecException,
java.security.NoSuchAlgorithmException
java.security.spec.InvalidKeySpecException
java.security.NoSuchAlgorithmException| Method Detail |
|---|
public boolean equals(java.lang.Object obj)
equals in class java.lang.ObjectObject.equals(Object)public java.lang.String getAlgorithm()
getAlgorithm in interface java.security.KeySecretKey.getAlgorithm()public byte[] getEncoded()
getEncoded in interface java.security.KeySecretKey.getEncoded()public java.lang.String getFormat()
getFormat in interface java.security.KeySecretKey.getFormat()public javax.crypto.spec.PBEParameterSpec getParamSpec()
public int hashCode()
hashCode in class java.lang.ObjectObject.hashCode()public java.lang.String toString()
toString in class java.lang.ObjectObject.toString()