Package com.google.crypto.tink.tinkkey
Class KeyHandle
- java.lang.Object
-
- com.google.crypto.tink.tinkkey.KeyHandle
-
- Direct Known Subclasses:
InternalKeyHandle
@Immutable public class KeyHandle extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classKeyHandle.KeyStatusTypeKeyStatusType is metadata associated to a key which is only meaningful when the key is part of aKeyset.
-
Constructor Summary
Constructors Modifier Constructor Description protectedKeyHandle(TinkKey key, KeyHandle.KeyStatusType status, int keyId)Constructor intended for Tink internal purposes; allows one to set all the member variables of aKeyHandle.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static KeyHandlecreateFromKey(com.google.crypto.tink.proto.KeyData keyData, KeyTemplate.OutputPrefixType opt)static KeyHandlecreateFromKey(TinkKey key, KeyAccess access)static KeyHandlegenerateNew(KeyTemplate keyTemplate)Generates a newKeyHandlethat contains a fresh key generated according tokeyTemplate.intgetId()Returns the key ID of this key.TinkKeygetKey(KeyAccess access)Returns the underlyingTinkKeykey ifaccessis aSecretKeyAccessand the key has a secret, or if the key does not have a secret, otherwise throws aGeneralSecurityException.KeyTemplategetKeyTemplate()Returns theKeyTemplateof the underlyingTinkKey.KeyHandle.KeyStatusTypegetStatus()Returns the status of the key.booleanhasSecret()Returnstrueif the underlyingTinkKeyhas a secret.
-
-
-
Constructor Detail
-
KeyHandle
protected KeyHandle(TinkKey key, KeyHandle.KeyStatusType status, int keyId)
Constructor intended for Tink internal purposes; allows one to set all the member variables of aKeyHandle.
-
-
Method Detail
-
createFromKey
public static KeyHandle createFromKey(TinkKey key, KeyAccess access) throws java.security.GeneralSecurityException
Returns aKeyHandleinstance withkeyas the underlyingTinkKeyif the caller provides the correctKeyAccessinstance.- Throws:
java.security.GeneralSecurityException- ifaccessdoes not grant access tokey
-
createFromKey
public static KeyHandle createFromKey(com.google.crypto.tink.proto.KeyData keyData, KeyTemplate.OutputPrefixType opt)
-
generateNew
public static KeyHandle generateNew(KeyTemplate keyTemplate) throws java.security.GeneralSecurityException
Generates a newKeyHandlethat contains a fresh key generated according tokeyTemplate.- Throws:
java.security.GeneralSecurityException- if the key template's type URL has not been registered with theRegistry.
-
hasSecret
public boolean hasSecret()
Returnstrueif the underlyingTinkKeyhas a secret.
-
getStatus
public KeyHandle.KeyStatusType getStatus()
Returns the status of the key. SeeKeyHandle.KeyStatusType.
-
getId
public int getId()
Returns the key ID of this key. The key ID is not guaranteed to be unique among all KeyHandles.
-
getKey
public TinkKey getKey(KeyAccess access) throws java.security.GeneralSecurityException
Returns the underlyingTinkKeykey ifaccessis aSecretKeyAccessand the key has a secret, or if the key does not have a secret, otherwise throws aGeneralSecurityException.- Throws:
java.security.GeneralSecurityException
-
getKeyTemplate
public KeyTemplate getKeyTemplate()
Returns theKeyTemplateof the underlyingTinkKey.- Throws:
java.lang.UnsupportedOperationException- if the underlyingTinkKeyhas not implemented getKeyTemplate().
-
-