@Immutable public class KeyHandle extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
KeyHandle.KeyStatusType
KeyStatusType is metadata associated to a key which is only meaningful when the key is part of
a
Keyset. |
| Modifier | Constructor and Description |
|---|---|
protected |
KeyHandle(TinkKey key,
KeyHandle.KeyStatusType status,
int keyId)
Constructor intended for Tink internal purposes; allows one to set all the member variables of
a
KeyHandle. |
| Modifier and Type | Method and Description |
|---|---|
static KeyHandle |
createFromKey(KeyData keyData,
KeyTemplate.OutputPrefixType opt)
|
static KeyHandle |
createFromKey(TinkKey key,
KeyAccess access)
|
static KeyHandle |
generateNew(KeyTemplate keyTemplate)
Generates a new
KeyHandle that contains a fresh key generated according to keyTemplate. |
int |
getId()
Returns the key ID of this key.
|
TinkKey |
getKey(KeyAccess access)
Returns the underlying
TinkKey key if access is a SecretKeyAccess and
the key has a secret, or if the key does not have a secret, otherwise throws a GeneralSecurityException. |
KeyTemplate |
getKeyTemplate()
Returns the
KeyTemplate of the underlying TinkKey. |
KeyHandle.KeyStatusType |
getStatus()
Returns the status of the key.
|
boolean |
hasSecret()
Returns
true if the underlying TinkKey has a secret. |
protected KeyHandle(TinkKey key, KeyHandle.KeyStatusType status, int keyId)
KeyHandle.public static KeyHandle createFromKey(TinkKey key, KeyAccess access) throws GeneralSecurityException
KeyHandle instance with key as the underlying TinkKey if the
caller provides the correct KeyAccess instance.GeneralSecurityException - if access does not grant access to keypublic static KeyHandle createFromKey(KeyData keyData, KeyTemplate.OutputPrefixType opt)
public static KeyHandle generateNew(KeyTemplate keyTemplate) throws GeneralSecurityException
KeyHandle that contains a fresh key generated according to keyTemplate.GeneralSecurityException - if the key template's type URL has not been registered with
the Registry.public boolean hasSecret()
true if the underlying TinkKey has a secret.public KeyHandle.KeyStatusType getStatus()
KeyHandle.KeyStatusType.public int getId()
public TinkKey getKey(KeyAccess access) throws GeneralSecurityException
TinkKey key if access is a SecretKeyAccess and
the key has a secret, or if the key does not have a secret, otherwise throws a GeneralSecurityException.GeneralSecurityExceptionpublic KeyTemplate getKeyTemplate()
KeyTemplate of the underlying TinkKey.UnsupportedOperationException - if the underlying TinkKey has not implemented
getKeyTemplate().