public class PBEKeyBMP
extends java.lang.Object
implements javax.crypto.SecretKey
PKCS#12 breaks with the recommendation of PKCS#5 suggesting passwords to consist of printable ASCII characters. PKCS #12 creates passwords from BMPStrings with a NULL terminator by encoding every character of the original BMPString in 2 bytes in big-endian format (most-significant byte first).
This class returns the password as a byte array of the default ASCII encoding. But
in contrast to PBEKey
here the password is created from a BMPstring with
a NULL terminator.
E.g.: User-password "Beavis" would lead to the following string of 14 bytes:
0x00 0x42 0x00 0x65 0x00 0x61 0x00 0x76 0x00 0x69 0x00 0x73 0x00 0x00
Constructor and Description |
---|
PBEKeyBMP(char[] password)
Creates a new PBEKeyBMP from a char array.
|
PBEKeyBMP(javax.crypto.spec.PBEKeySpec keySpec)
Creates a new PBEKey from a PBEKeySpec.
|
PBEKeyBMP(java.lang.String password)
Creates a new PBEKeyBMP from a String.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getAlgorithm()
Returns the algorithm name.
|
byte[] |
getEncoded()
Returns the password as byte array.
|
static byte[] |
getEncoded(char[] password)
Converts the ASCII password to a 2 bytes big-endian format BMPString.
|
java.lang.String |
getFormat()
Returns the format name.
|
char[] |
getKey()
Returns the password as char array.
|
void |
setAlgorithm(java.lang.String algorithm)
Sets the algorithm name.
|
public PBEKeyBMP(java.lang.String password)
password
- the password as a stringpublic PBEKeyBMP(char[] password)
password
- the password as a char arraypublic PBEKeyBMP(javax.crypto.spec.PBEKeySpec keySpec)
keySpec
- the password as KeySpecpublic final byte[] getEncoded()
getEncoded
in interface java.security.Key
public static final byte[] getEncoded(char[] password)
If null
is specified as password the encoding returned by
this method consists of two 0X00 bytes.
public char[] getKey()
public void setAlgorithm(java.lang.String algorithm)
algorithm
- the algorithm namepublic java.lang.String getAlgorithm()
getAlgorithm
in interface java.security.Key
public java.lang.String getFormat()
getFormat
in interface java.security.Key