|
IAIK PKCS#11 Provider Micro Edition version 1.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectiaik.pkcs.pkcs11.me.Key
Keys of this class represent keys on the associated token.
Such keys can be used with Signature
and
Cipher
object of the same token.
It is impossible to use keys of one token with algorithms of another
token.
Basically, a key can be a (asymmetric) private key, a public key or
a (symmetric) secret key. This is called the key type. The constants
starting with TYPE_
are used to identify the type. Use
getType()
to get the key's type.
In addition, keys have flags indicating their allowed usage; e.g.
a private key can be valid for signature creation but not for decryption.
The application can call canBeUsedFor(long)
to check if a certain
usage is allowed.
Key key = ... if (key.canBeUsedFor(Key.USAGE_SIGNATURE_CREATION)) { ... // create a signature }Notice that private keys may only be allowed for signature creation and decryption. Public keys may only be used for signature verification and encryption. Secrete keys may be used for either of these purposes. One key may even have more than one allowed key usage; e.g. a private key may be valid for signature creation as well as for decryption.
This class also supports getting the key material from such a
token key. This is especially useful if the token generates keys
which must be exported from the token. For instance, the public key
of a RSA key-pair. Usually, the application must export the public key
to apply for a certificate at a CA service. getComponent(long)
can be used to get a component of a key.
Field Summary | |
static java.lang.String |
ALGORITHM_AES
Algorithm identifier for AES keys. |
static java.lang.String |
ALGORITHM_DES
Algorithm identifier for DES keys. |
static java.lang.String |
ALGORITHM_DESEDE
Algorithm identifier for Triple DES keys. |
static java.lang.String |
ALGORITHM_DH
Algorithm identifier for Diffie-Hellman keys. |
static java.lang.String |
ALGORITHM_DSA
Algorithm identifier for DSA keys. |
static java.lang.String |
ALGORITHM_EC
Algorithm identifier for elliptic curve keys. |
static java.lang.String |
ALGORITHM_ECDSA
Algorithm identifier for elliptic curve DSA keys. |
static java.lang.String |
ALGORITHM_GENERIC
Algorithm identifier for generic symmetric keys. |
static java.lang.String |
ALGORITHM_IDEA
Algorithm identifier for IDEA keys. |
static java.lang.String |
ALGORITHM_RC2
Algorithm identifier for RC2 keys. |
static java.lang.String |
ALGORITHM_RC4
Algorithm identifier for RC4 keys. |
static java.lang.String |
ALGORITHM_RSA
Algorithm identifier for RSA keys. |
static long |
COMPONENT_COEFFICIENT
Component identifier for the CRT coefficient component of private RSA CRT keys. |
static long |
COMPONENT_EXPONENT_1
Component identifier for the prime exponent 1 component of private RSA CRT keys. |
static long |
COMPONENT_EXPONENT_2
Component identifier for the prime exponent 2 component of private RSA CRT keys. |
static long |
COMPONENT_MODULUS
Component identifier for the modulus component of RSA keys. |
static long |
COMPONENT_PRIME_1
Component identifier for the prime 1 component of private RSA CRT keys. |
static long |
COMPONENT_PRIME_2
Component identifier for the prime 2 component of private RSA CRT keys. |
static long |
COMPONENT_PRIVATE_EXPONENT
Component identifier for the private exponent component of RSA private keys. |
static long |
COMPONENT_PUBLIC_EXPONENT
Component identifier for the public exponent component of RSA keys. |
static long |
COMPONENT_VALUE
Component identifier for the value component of symmetric keys. |
static long |
COMPONENT_VALUE_LENGTH
Component identifier for the value length of secret keys. |
static long |
TYPE_PRIVATE_KEY
Key type constant for private (asymmetric) keys. |
static long |
TYPE_PUBLIC_KEY
Key type constant for public keys. |
static long |
TYPE_SECRET_KEY
Key type constant for secret (symmetric) keys. |
static long |
USAGE_DECRYPTION
Key usage identifier for decryption. |
static long |
USAGE_ENCRYPTION
Key usage identifier for encryption. |
static long |
USAGE_SIGNATURE_CREATION
Key usage identifier for signature creation. |
static long |
USAGE_SIGNATURE_VERIFICATION
Key usage identifier for signature verification. |
static long |
USAGE_UNWRAP
Key usage identifier for key-unwrapping. |
static long |
USAGE_WRAP
Key usage identifier for key-wrapping. |
Method Summary | |
boolean |
canBeUsedFor(long usage)
This method determines if this key can be used for a certain purpose. |
java.lang.String |
getAlgorithm()
Get the algorithm name of this key. |
java.lang.Object |
getComponent(long componentType)
Get a specific component of this key; e.g. the modulus of an RSA key, or the value of a secret key. |
long |
getType()
Get the key type. |
void |
releaseSession()
If this key is not a key which is permanently stored on the token (e.g. a temporary secret key), this method releases the session of the key. |
void |
setComponent(long componentType,
java.lang.Object componentValue)
Set a specific component of this key; e.g. the modulus of an RSA key, or the value of a secret key. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final long TYPE_PRIVATE_KEY
public static final long TYPE_PUBLIC_KEY
public static final long TYPE_SECRET_KEY
public static final java.lang.String ALGORITHM_RSA
public static final java.lang.String ALGORITHM_DSA
public static final java.lang.String ALGORITHM_DH
public static final java.lang.String ALGORITHM_EC
public static final java.lang.String ALGORITHM_ECDSA
public static final java.lang.String ALGORITHM_AES
public static final java.lang.String ALGORITHM_DES
public static final java.lang.String ALGORITHM_DESEDE
public static final java.lang.String ALGORITHM_IDEA
public static final java.lang.String ALGORITHM_RC2
public static final java.lang.String ALGORITHM_RC4
public static final java.lang.String ALGORITHM_GENERIC
public static final long COMPONENT_VALUE
public static final long COMPONENT_MODULUS
public static final long COMPONENT_PUBLIC_EXPONENT
public static final long COMPONENT_PRIVATE_EXPONENT
public static final long COMPONENT_PRIME_1
public static final long COMPONENT_PRIME_2
public static final long COMPONENT_EXPONENT_1
public static final long COMPONENT_EXPONENT_2
public static final long COMPONENT_COEFFICIENT
public static final long COMPONENT_VALUE_LENGTH
public static final long USAGE_SIGNATURE_CREATION
public static final long USAGE_SIGNATURE_VERIFICATION
public static final long USAGE_ENCRYPTION
public static final long USAGE_DECRYPTION
public static final long USAGE_WRAP
public static final long USAGE_UNWRAP
Method Detail |
public boolean canBeUsedFor(long usage) throws PKCS11RuntimeException
usage
values are all constants
starting with USAGE_
; e.g. USAGE_SIGNATURE_CREATION
.
usage
- The usage identifier; e.g. USAGE_SIGNATURE_CREATION
.
true
if this key can be used for this purpose.
PKCS11RuntimeException
- If getting the key required key
attribute fails.public java.lang.String getAlgorithm() throws PKCS11RuntimeException
The known algorithms are all constants of this class which start
with ALGORITHM_
.
PKCS11RuntimeException
- If getting the key type attribute fails.public long getType()
TYPE_PRIVATE_KEY
,
TYPE_PUBLIC_KEY
or TYPE_SECRET_KEY
.
public java.lang.Object getComponent(long componentType) throws PKCS11Exception, PKCS11RuntimeException
COMPONENT_
.
Primitive values like long
values or byte
values are returned as their corresponding object types; e.g.
java.lang.Long
or java.lang.Byte
. Arrays
are returned as arrays of the primitive type; e.g. byte arrays are
returned as byte[]
type. Strings are returned as
char[]
type.
This method will return null
if the attribute
is present in the object and has the value null
, and
if the attribute is present but is sensitive (i.e. protected);e.g
the private exponent of RSA private keys.
If the key does not possess the requested component, this
method will throw the checked exception PKCS11Exception
.
For example, if the application tries to get the
COMPONENT_MODULUS
from a DES key.
componentType
- The requested component; e.g.
COMPONENT_MODULUS
for a RSA key.
null
if the value is
actually null
or sensitive.
PKCS11Exception
- If the key does not possess the requested
component.
PKCS11RuntimeException
- If getting the component failed
for some other reason.public void setComponent(long componentType, java.lang.Object componentValue) throws PKCS11Exception, PKCS11RuntimeException
COMPONENT_
.
Primitive values like long
values or byte
values are given as their corresponding object types; e.g.
java.lang.Long
or java.lang.Byte
. Arrays
are specified as arrays of the primitive type; e.g. byte arrays are
returned as byte[]
type. Strings are expected as
char[]
type.
This method accepts null
for the attribute
value.
If the key does not possess the specified component
or if the specified component is sensitive, this
method will throw the checked exception PKCS11Exception
.
For example, if the application tries to set the
COMPONENT_MODULUS
component in a DES key.
componentType
- The requested component; e.g.
COMPONENT_MODULUS
for a RSA key.componentValue
- The component value or null
.
PKCS11Exception
- If the key does not possess the requested
component or if it is sensitive.
PKCS11RuntimeException
- If setting the component failed
for some other reason.public void releaseSession() throws PKCS11RuntimeException
PKCS11RuntimeException
- If releasing the session fails.
|
IAIK PKCS#11 Provider Micro Edition version 1.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |