Package org.mozilla.jss.pkcs11
Class PK11KeyWrapper
- java.lang.Object
-
- org.mozilla.jss.pkcs11.PK11KeyWrapper
-
- All Implemented Interfaces:
KeyWrapper
public final class PK11KeyWrapper extends java.lang.Object implements KeyWrapper
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
initUnwrap()
For plaintext-wrapped keys.void
initUnwrap(PrivateKey unwrappingKey, java.security.spec.AlgorithmParameterSpec parameters)
void
initUnwrap(SymmetricKey unwrappingKey, java.security.spec.AlgorithmParameterSpec parameters)
void
initWrap()
For wrapping keys in plaintext.void
initWrap(java.security.PublicKey wrappingKey, java.security.spec.AlgorithmParameterSpec parameters)
void
initWrap(SymmetricKey wrappingKey, java.security.spec.AlgorithmParameterSpec parameters)
PrivateKey
unwrapPrivate(byte[] wrapped, PrivateKey.Type type, java.security.PublicKey publicKey)
Unwraps a private key, creating a permanent private key object.SymmetricKey
unwrapSymmetric(byte[] wrapped, SymmetricKey.Type type, int keyLen)
Unwraps a key and allows it to be used for all operations.SymmetricKey
unwrapSymmetric(byte[] wrapped, SymmetricKey.Type type, SymmetricKey.Usage usage, int keyLen)
SymmetricKey
unwrapSymmetricPerm(byte[] wrapped, SymmetricKey.Type type, int keyLen)
Unwraps a key and allows it to be used for all operations.SymmetricKey
unwrapSymmetricPerm(byte[] wrapped, SymmetricKey.Type type, SymmetricKey.Usage usage, int keyLen)
PrivateKey
unwrapTemporaryPrivate(byte[] wrapped, PrivateKey.Type type, java.security.PublicKey publicKey)
Unwraps a private key, creating a temporary private key object.byte[]
wrap(PrivateKey toBeWrapped)
byte[]
wrap(SymmetricKey toBeWrapped)
-
-
-
Method Detail
-
initWrap
public void initWrap(SymmetricKey wrappingKey, java.security.spec.AlgorithmParameterSpec parameters) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
- Specified by:
initWrap
in interfaceKeyWrapper
- Throws:
java.security.InvalidKeyException
java.security.InvalidAlgorithmParameterException
-
initWrap
public void initWrap(java.security.PublicKey wrappingKey, java.security.spec.AlgorithmParameterSpec parameters) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
- Specified by:
initWrap
in interfaceKeyWrapper
- Throws:
java.security.InvalidKeyException
java.security.InvalidAlgorithmParameterException
-
initWrap
public void initWrap() throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
Description copied from interface:KeyWrapper
For wrapping keys in plaintext.- Specified by:
initWrap
in interfaceKeyWrapper
- Throws:
java.security.InvalidKeyException
java.security.InvalidAlgorithmParameterException
-
initUnwrap
public void initUnwrap(PrivateKey unwrappingKey, java.security.spec.AlgorithmParameterSpec parameters) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
- Specified by:
initUnwrap
in interfaceKeyWrapper
- Throws:
java.security.InvalidKeyException
java.security.InvalidAlgorithmParameterException
-
initUnwrap
public void initUnwrap(SymmetricKey unwrappingKey, java.security.spec.AlgorithmParameterSpec parameters) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
- Specified by:
initUnwrap
in interfaceKeyWrapper
- Throws:
java.security.InvalidKeyException
java.security.InvalidAlgorithmParameterException
-
initUnwrap
public void initUnwrap() throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
Description copied from interface:KeyWrapper
For plaintext-wrapped keys.- Specified by:
initUnwrap
in interfaceKeyWrapper
- Throws:
java.security.InvalidKeyException
java.security.InvalidAlgorithmParameterException
-
wrap
public byte[] wrap(PrivateKey toBeWrapped) throws java.security.InvalidKeyException, java.lang.IllegalStateException, TokenException
- Specified by:
wrap
in interfaceKeyWrapper
- Throws:
java.security.InvalidKeyException
java.lang.IllegalStateException
TokenException
-
wrap
public byte[] wrap(SymmetricKey toBeWrapped) throws java.security.InvalidKeyException, java.lang.IllegalStateException, TokenException
- Specified by:
wrap
in interfaceKeyWrapper
- Throws:
java.security.InvalidKeyException
java.lang.IllegalStateException
TokenException
-
unwrapPrivate
public PrivateKey unwrapPrivate(byte[] wrapped, PrivateKey.Type type, java.security.PublicKey publicKey) throws TokenException, java.security.InvalidKeyException, java.lang.IllegalStateException
Unwraps a private key, creating a permanent private key object. A permanent private key object resides on a token until it is explicitly deleted from the token.- Specified by:
unwrapPrivate
in interfaceKeyWrapper
publicKey
- Used to calculate the key identifier that must be stored with the private key. Must be aRSAPublicKey
or aDSAPublicKey
.- Throws:
java.security.InvalidKeyException
- If the type of the public key does not match the type of the private key to be unwrapped.TokenException
java.lang.IllegalStateException
-
unwrapTemporaryPrivate
public PrivateKey unwrapTemporaryPrivate(byte[] wrapped, PrivateKey.Type type, java.security.PublicKey publicKey) throws TokenException, java.security.InvalidKeyException, java.lang.IllegalStateException
Unwraps a private key, creating a temporary private key object. A temporary private key is one that does not permanently reside on a token. As soon as it is garbage-collected, it is gone forever.- Specified by:
unwrapTemporaryPrivate
in interfaceKeyWrapper
publicKey
- Used to calculate the key identifier that must be stored with the private key. Must be aRSAPublicKey
or aDSAPublicKey
.- Throws:
java.security.InvalidKeyException
- If the type of the public key does not match the type of the private key to be unwrapped.TokenException
java.lang.IllegalStateException
-
unwrapSymmetric
public SymmetricKey unwrapSymmetric(byte[] wrapped, SymmetricKey.Type type, SymmetricKey.Usage usage, int keyLen) throws TokenException, java.lang.IllegalStateException, java.security.InvalidAlgorithmParameterException
- Specified by:
unwrapSymmetric
in interfaceKeyWrapper
usage
- The operation the key will be used for after it is unwrapped. You have to specify this so that the key can be properly marked with the operation it supports. Some PKCS #11 tokens require that a key be marked for an operation before it can perform that operation.keyLen
- The expected length of the key in bytes. This is only used for variable-length keys (RC4) and non-padding algorithms. Otherwise, it can be set to anything(like 0).- Throws:
TokenException
java.lang.IllegalStateException
java.security.InvalidAlgorithmParameterException
-
unwrapSymmetric
public SymmetricKey unwrapSymmetric(byte[] wrapped, SymmetricKey.Type type, int keyLen) throws TokenException, java.lang.IllegalStateException, java.security.InvalidAlgorithmParameterException
Description copied from interface:KeyWrapper
Unwraps a key and allows it to be used for all operations.- Specified by:
unwrapSymmetric
in interfaceKeyWrapper
keyLen
- The expected length of the key in bytes. This is only used for variable-length keys (RC4) and non-padding algorithms. Otherwise, it can be set to anything(like 0).- Throws:
TokenException
java.lang.IllegalStateException
java.security.InvalidAlgorithmParameterException
-
unwrapSymmetricPerm
public SymmetricKey unwrapSymmetricPerm(byte[] wrapped, SymmetricKey.Type type, SymmetricKey.Usage usage, int keyLen) throws TokenException, java.lang.IllegalStateException, java.security.InvalidAlgorithmParameterException
- Specified by:
unwrapSymmetricPerm
in interfaceKeyWrapper
- Throws:
TokenException
java.lang.IllegalStateException
java.security.InvalidAlgorithmParameterException
-
unwrapSymmetricPerm
public SymmetricKey unwrapSymmetricPerm(byte[] wrapped, SymmetricKey.Type type, int keyLen) throws TokenException, java.lang.IllegalStateException, java.security.InvalidAlgorithmParameterException
Description copied from interface:KeyWrapper
Unwraps a key and allows it to be used for all operations.- Specified by:
unwrapSymmetricPerm
in interfaceKeyWrapper
keyLen
- The expected length of the key in bytes. This is only used for variable-length keys (RC4) and non-padding algorithms. Otherwise, it can be set to anything(like 0).- Throws:
TokenException
java.lang.IllegalStateException
java.security.InvalidAlgorithmParameterException
-
-