Top Description Fields Constructors Methods
sun.security.provider

pack-priv final Class KeyProtector

extends Object
Class Inheritance
Imports
java.io.IOException, java.security.SecureRandom, java.security.*, java.util.Arrays, sun.security.pkcs.EncryptedPrivateKeyInfo, .PKCS8Key, sun.security.util.KnownOIDs, .ObjectIdentifier, sun.security.x509.AlgorithmId

This is an implementation of a Sun proprietary, exportable algorithm intended for use when protecting (or recovering the cleartext version of) sensitive keys. This algorithm is not intended as a general purpose cipher. This is how the algorithm works for key protection: p - user password s - random salt X - xor key P - to-be-protected key Y - protected key R - what gets stored in the keystore Step 1: Take the user's password, append a random salt (of fixed size) to it, and hash it: d1 = digest(p, s) Store d1 in X. Step 2: Take the user's password, append the digest result from the previous step, and hash it: dn = digest(p, dn-1). Store dn in X (append it to the previously stored digests). Repeat this step until the length of X matches the length of the private key P. Step 3: XOR X and P, and store the result in Y: Y = X XOR P. Step 4: Store s, Y, and digest(p, P) in the result buffer R: R = s + Y + digest(p, P), where "+" denotes concatenation. (NOTE: digest(p, P) is stored in the result buffer, so that when the key is recovered, we can check if the recovered key indeed matches the original key.) R is stored in the keystore. The protected key is recovered as follows: Step1 and Step2 are the same as above, except that the salt is not randomly generated, but taken from the result R of step 4 (the first length(s) bytes). Step 3 (XOR operation) yields the plaintext key. Then concatenate the password with the recovered key, and compare with the last length(digest(p, P)) bytes of R. If they match, the recovered key is indeed the same key as the original key.
Author
Jan Luehe
Since
1.2
See Also
java.security.KeyStore, JavaKeyStore, KeyTool

Field Summary

Modifier and TypeField and Description
private static final String
private static final int
private final MessageDigest
private byte[]
private static final int

Constructor Summary

AccessConstructor and Description
public
KeyProtector(byte[] passwordBytes)

Creates an instance of this class, and initializes it with the given password.

Method Summary

Modifier and TypeMethod and Description
public byte[]
protect(Key key)

public Key
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DIGEST_ALGback to summary
private static final String DIGEST_ALG
DIGEST_LENback to summary
private static final int DIGEST_LEN
mdback to summary
private final MessageDigest md
passwdBytesback to summary
private byte[] passwdBytes
SALT_LENback to summary
private static final int SALT_LEN

Constructor Detail

KeyProtectorback to summary
public KeyProtector(byte[] passwordBytes) throws NoSuchAlgorithmException

Creates an instance of this class, and initializes it with the given password.

Method Detail

protectback to summary
public byte[] protect(Key key) throws KeyStoreException
recoverback to summary
public Key recover(EncryptedPrivateKeyInfo encrInfo) throws UnrecoverableKeyException