Class Registry
- java.lang.Object
-
- com.google.crypto.tink.Registry
-
public final class Registry extends java.lang.ObjectA global container of key managers and catalogues.Registry maps each supported key type to a corresponding
KeyManagerobject, which "understands" the key type (i.e., the KeyManager can instantiate the primitive corresponding to given key, or can generate new keys of the supported key type). It holds also aPrimitiveWrapperfor each supported primitive, so that it can wrap a set of primitives (corresponding to a keyset) into a single primitive.Keeping KeyManagers for all primitives in a single Registry (rather than having a separate KeyManager per primitive) enables modular construction of compound primitives from "simple" ones, e.g., AES-CTR-HMAC AEAD encryption uses IND-CPA encryption and a MAC.
Registry is initialized at startup, and is later used to instantiate primitives for given keys or keysets. Note that regular users will usually not work directly with Registry, but rather via
TinkConfigandKeysetHandle.getPrimitive(Class)-methods, which in the background register and query the Registry for specific KeyManagers and PrimitiveWrappers. Registry is public though, to enable configurations with custom catalogues, primitives or KeyManagers.To initialize the Registry with all key managers:
TinkConfig.register();Here's how to register only
Aeadkey managers:AeadConfig.register();After the Registry has been initialized, one can use get a primitive as follows:
KeysetHandle keysetHandle = ...; Aead aead = keysetHandle.getPrimitive(RegistryConfiguration.get(), Aead.class);- Since:
- 1.0.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voidaddCatalogue(java.lang.String catalogueName, Catalogue<?> catalogue)Deprecated.Catalogues are no longer supported.static Catalogue<?>getCatalogue(java.lang.String catalogueName)Deprecated.Catalogues are no longer supported.static <P> KeyManager<P>getKeyManager(java.lang.String typeUrl, java.lang.Class<P> primitiveClass)Deprecated.KeyManagers should not be used directly.static <P> PgetPrimitive(com.google.crypto.tink.proto.KeyData keyData, java.lang.Class<P> primitiveClass)Deprecated.Use the standard API instead or file an issue on https://github.com/tink-crypto/tink-java, explaining your use case.static <P> PgetPrimitive(java.lang.String typeUrl, byte[] serializedKey, java.lang.Class<P> primitiveClass)Deprecated.Use the standard API instead or file an issue on https://github.com/tink-crypto/tink-java, explaining your use case.static <P> PgetPrimitive(java.lang.String typeUrl, com.google.protobuf.ByteString serializedKey, java.lang.Class<P> primitiveClass)Deprecated.Use the standard API instead or file an issue on https://github.com/tink-crypto/tink-java, explaining your use case.static <P> PgetPrimitive(java.lang.String typeUrl, com.google.protobuf.MessageLite key, java.lang.Class<P> primitiveClass)Deprecated.UsegetPrimitive(typeUrl, serializedKey, Primitive.classinstead.static com.google.crypto.tink.proto.KeyDatagetPublicKeyData(java.lang.String typeUrl, com.google.protobuf.ByteString serializedPrivateKey)Deprecated.Instead, users should have their keys in aKeysetHandleand callkeysetHandle.getPublicKeysetHandle.static KeyManager<?>getUntypedKeyManager(java.lang.String typeUrl)Deprecated.KeyManagers should not be used directly.static java.util.List<java.lang.String>keyTemplates()Returns an immutable list of key template names supported by registered key managers that are allowed to generate new keys.static com.google.protobuf.MessageLitenewKey(com.google.crypto.tink.proto.KeyTemplate keyTemplate)Deprecated.UsenewKeyDatainstead.static com.google.protobuf.MessageLitenewKey(java.lang.String typeUrl, com.google.protobuf.MessageLite format)Deprecated.UsenewKeyDatainstead.static com.google.crypto.tink.proto.KeyDatanewKeyData(KeyTemplate keyTemplate)Deprecated.UseKeysetHandle.generateNew(keyTemplate.toParameters())instead and use the Keyset Handle API.static com.google.crypto.tink.proto.KeyDatanewKeyData(com.google.crypto.tink.proto.KeyTemplate keyTemplate)Deprecated.UseKeysetHandle.generateNewwith a Parameters object instead.static <P> voidregisterKeyManager(KeyManager<P> manager)Tries to registermanagerformanager.getKeyType().static <P> voidregisterKeyManager(KeyManager<P> manager, boolean newKeyAllowed)Tries to registermanagerformanager.getKeyType().static <P> voidregisterKeyManager(java.lang.String typeUrl, KeyManager<P> manager)Deprecated.static <P> voidregisterKeyManager(java.lang.String typeUrl, KeyManager<P> manager, boolean newKeyAllowed)Deprecated.static voidrestrictToFipsIfEmpty()Tries to enable the FIPS restrictions if the Registry is empty.
-
-
-
Method Detail
-
addCatalogue
@Deprecated public static void addCatalogue(java.lang.String catalogueName, Catalogue<?> catalogue) throws java.security.GeneralSecurityExceptionDeprecated.Catalogues are no longer supported.Tries to add a catalogue, to enable custom configuration of key types and key managers.Adding a custom catalogue should be a one-time operaton. There is an existing catalogue, throw exception if
catalogueand the existing catalogue aren't instances of the same class, and do nothing if they are.- Throws:
java.security.GeneralSecurityException- if there's an existing catalogue and it is not an instance of the same class ascatalogue
-
getCatalogue
@Deprecated public static Catalogue<?> getCatalogue(java.lang.String catalogueName) throws java.security.GeneralSecurityException
Deprecated.Catalogues are no longer supported.Tries to get a catalogue associated withcatalogueName.- Throws:
java.security.GeneralSecurityException- if no catalogue is found
-
registerKeyManager
public static <P> void registerKeyManager(KeyManager<P> manager) throws java.security.GeneralSecurityException
Tries to registermanagerformanager.getKeyType(). Users can generate new keys with this manager using thenewKey(com.google.crypto.tink.proto.KeyTemplate)methods.If there is an existing key manager, throws an exception if
managerand the existing key manager aren't instances of the same class, or the existing key manager could not create new keys. Otherwise registration succeeds.- Throws:
java.security.GeneralSecurityException- if there's an existing key manager is not an instance of the class ofmanager, or the registration tries to re-enable the generation of new keys.
-
registerKeyManager
public static <P> void registerKeyManager(KeyManager<P> manager, boolean newKeyAllowed) throws java.security.GeneralSecurityException
Tries to registermanagerformanager.getKeyType(). IfnewKeyAllowedis true, users can generate new keys with this manager using thenewKey(com.google.crypto.tink.proto.KeyTemplate)methods.If there is an existing key manager, throws an exception if
managerand the existing key manager aren't instances of the same class, or ifnewKeyAllowedis true while the existing key manager could not create new keys. Otherwise registration succeeds.- Throws:
java.security.GeneralSecurityException- if there's an existing key manager is not an instance of the class ofmanager, or the registration tries to re-enable the generation of new keys.
-
registerKeyManager
@Deprecated public static <P> void registerKeyManager(java.lang.String typeUrl, KeyManager<P> manager) throws java.security.GeneralSecurityExceptionDeprecated.Tries to registermanagerfor the giventypeUrl. Users can generate new keys with this manager using thenewKey(com.google.crypto.tink.proto.KeyTemplate)methods.Does nothing if there's an existing key manager and it's an instance of the same class as
manager.- Throws:
java.security.GeneralSecurityException- if there's an existing key manager and it is not an instance of the same class asmanager
-
registerKeyManager
@Deprecated public static <P> void registerKeyManager(java.lang.String typeUrl, KeyManager<P> manager, boolean newKeyAllowed) throws java.security.GeneralSecurityExceptionDeprecated.Tries to registermanagerfor the giventypeUrl. IfnewKeyAllowedis true, users can generate new keys with this manager using thenewKey(com.google.crypto.tink.proto.KeyTemplate)methods.Does nothing if there's an existing key manager and it's an instance of the same class as
manager.- Throws:
java.security.GeneralSecurityException- if there's an existing key manager and it is not an instance of the same class asmanager
-
getKeyManager
@Deprecated public static <P> KeyManager<P> getKeyManager(java.lang.String typeUrl, java.lang.Class<P> primitiveClass) throws java.security.GeneralSecurityException
Deprecated.KeyManagers should not be used directly. UsenewKeyDataorgetPrimitiveinstead.Returns aKeyManagerfor the giventypeUrl(if found).- Throws:
java.security.GeneralSecurityException
-
getUntypedKeyManager
@Deprecated public static KeyManager<?> getUntypedKeyManager(java.lang.String typeUrl) throws java.security.GeneralSecurityException
Deprecated.KeyManagers should not be used directly. UsenewKeyDataorgetPrimitiveinstead.Returns aKeyManagerfor the giventypeUrl(if found).- Throws:
java.security.GeneralSecurityException
-
newKeyData
@Deprecated public static com.google.crypto.tink.proto.KeyData newKeyData(com.google.crypto.tink.proto.KeyTemplate keyTemplate) throws java.security.GeneralSecurityExceptionDeprecated.UseKeysetHandle.generateNewwith a Parameters object instead. To convert a proto KeyTemplate to a parameters one can useTinkProtoParametersFormat.parse(t.toByteArray());Generates a newKeyDatafor the specifiedtemplate.It looks up a
KeyManageridentified bykeyTemplate.type_url, and callsKeyManager.newKeyData(com.google.protobuf.ByteString).This method should be used solely for key management.
- Returns:
- a new
KeyData - Throws:
java.security.GeneralSecurityException
-
newKeyData
@Deprecated public static com.google.crypto.tink.proto.KeyData newKeyData(KeyTemplate keyTemplate) throws java.security.GeneralSecurityException
Deprecated.UseKeysetHandle.generateNew(keyTemplate.toParameters())instead and use the Keyset Handle API.Generates a newKeyDatafor the specifiedtemplate.It looks up a
KeyManageridentified bykeyTemplate.type_url, and callsKeyManager.newKeyData(com.google.protobuf.ByteString).This method should be used solely for key management.
- Returns:
- a new
KeyData - Throws:
java.security.GeneralSecurityException
-
newKey
@Deprecated public static com.google.protobuf.MessageLite newKey(com.google.crypto.tink.proto.KeyTemplate keyTemplate) throws java.security.GeneralSecurityExceptionDeprecated.UsenewKeyDatainstead.Generates a new key for the specifiedkeyTemplate.It looks up a
KeyManageridentified bykeyTemplate.type_url, and callsKeyManager.newKey(com.google.protobuf.ByteString)withkeyTemplateas the parameter.- Returns:
- a new key
- Throws:
java.security.GeneralSecurityException
-
newKey
@Deprecated public static com.google.protobuf.MessageLite newKey(java.lang.String typeUrl, com.google.protobuf.MessageLite format) throws java.security.GeneralSecurityExceptionDeprecated.UsenewKeyDatainstead.Generates a new key for the specifiedformat.It looks up a
KeyManageridentified bykeyTemplate.type_url, and callsKeyManager.newKey(com.google.protobuf.ByteString)withformatas the parameter.- Returns:
- a new key
- Throws:
java.security.GeneralSecurityException
-
getPublicKeyData
@Deprecated public static com.google.crypto.tink.proto.KeyData getPublicKeyData(java.lang.String typeUrl, com.google.protobuf.ByteString serializedPrivateKey) throws java.security.GeneralSecurityExceptionDeprecated.Instead, users should have their keys in aKeysetHandleand callkeysetHandle.getPublicKeysetHandle.Extracts the public key data from the private key given inserializedPrivateKey.It looks up a
PrivateKeyManageridentified bytypeUrl, and callsPrivateKeyManager.getPublicKeyData(com.google.protobuf.ByteString)withserializedPrivateKeyas the parameter.- Returns:
- the public key of the corresponding private key
- Throws:
java.security.GeneralSecurityException
-
getPrimitive
@Deprecated public static <P> P getPrimitive(java.lang.String typeUrl, com.google.protobuf.MessageLite key, java.lang.Class<P> primitiveClass) throws java.security.GeneralSecurityExceptionDeprecated.UsegetPrimitive(typeUrl, serializedKey, Primitive.classinstead.Creates a new primitive for the key given inkey.It looks up a
KeyManageridentified bytype_url, and callsKeyManager.getPrimitive(com.google.protobuf.ByteString)withkeyas the parameter.- Returns:
- a new primitive
- Throws:
java.security.GeneralSecurityException
-
getPrimitive
@Deprecated public static <P> P getPrimitive(java.lang.String typeUrl, com.google.protobuf.ByteString serializedKey, java.lang.Class<P> primitiveClass) throws java.security.GeneralSecurityExceptionDeprecated.Use the standard API instead or file an issue on https://github.com/tink-crypto/tink-java, explaining your use case.Creates a new primitive for the key given inserializedKey.It looks up a
KeyManageridentified bytype_url, and callsKeyManager.getPrimitive(com.google.protobuf.ByteString)withserializedas the parameter.- Returns:
- a new primitive
- Throws:
java.security.GeneralSecurityException
-
getPrimitive
@Deprecated public static <P> P getPrimitive(java.lang.String typeUrl, byte[] serializedKey, java.lang.Class<P> primitiveClass) throws java.security.GeneralSecurityExceptionDeprecated.Use the standard API instead or file an issue on https://github.com/tink-crypto/tink-java, explaining your use case.Creates a new primitive for the key given inserializedKey.It looks up a
KeyManageridentified bytype_url, and callsKeyManager.getPrimitive(com.google.protobuf.ByteString)withserializedas the parameter.- Returns:
- a new primitive
- Throws:
java.security.GeneralSecurityException
-
getPrimitive
@Deprecated public static <P> P getPrimitive(com.google.crypto.tink.proto.KeyData keyData, java.lang.Class<P> primitiveClass) throws java.security.GeneralSecurityExceptionDeprecated.Use the standard API instead or file an issue on https://github.com/tink-crypto/tink-java, explaining your use case.Creates a new primitive for the key given inkeyData.It looks up a
KeyManageridentified bykeyData.type_url, and callsKeyManager.getPrimitive(com.google.protobuf.ByteString)withkeyData.valueas the parameter.- Returns:
- a new primitive
- Throws:
java.security.GeneralSecurityException
-
keyTemplates
public static java.util.List<java.lang.String> keyTemplates()
Returns an immutable list of key template names supported by registered key managers that are allowed to generate new keys.- Since:
- 1.6.0
-
restrictToFipsIfEmpty
public static void restrictToFipsIfEmpty() throws java.security.GeneralSecurityExceptionTries to enable the FIPS restrictions if the Registry is empty.- Throws:
java.security.GeneralSecurityException- if any key manager has already been registered.
-
-