/** * Tries to register {@code manager} for {@code manager.getKeyType()}. Users can generate new keys * with this manager using the {@link Registry#newKey} methods. * * <p>If there is an existing key manager, throws an exception if {@code manager} and 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 GeneralSecurityException if there's an existing key manager is not an instance * of the class of {@code manager}, or the registration tries to re-enable the generation * of new keys. */ public static synchronized <P> void registerKeyManager(final KeyManager<P> manager) throws GeneralSecurityException { registerKeyManager(manager, /* newKeyAllowed= */ true); }
/** * Tries to register {@code manager} for the given {@code typeUrl}. Users can generate new keys * with this manager using the {@link Registry#newKey} methods. * * <p>If there is an existing key manager, throw exception if {@code manager} and the existing * key manager aren't instances of the same class, and do nothing if they are. * * @throws GeneralSecurityException if there's an existing key manager is not an instance of the * class of {@code manager} * @deprecated use {@link #registerKeyManager(KeyManager<P>)} */ @Deprecated public static synchronized <P> void registerKeyManager( String typeUrl, final KeyManager<P> manager) throws GeneralSecurityException { registerKeyManager(typeUrl, manager, /* newKeyAllowed= */ true); }
AesCtrHmacAeadKeyManager() throws GeneralSecurityException { Registry.registerKeyManager(new AesCtrKeyManager()); }
/** * Tries to register {@code manager} for the given {@code typeUrl}. If {@code newKeyAllowed} is * true, users can generate new keys with this manager using the {@link Registry#newKey} methods. * * <p>If there is an existing key manager, throw exception if {@code manager} and the existing * key manager aren't instances of the same class, and do nothing if they are. * * @throws GeneralSecurityException if there's an existing key manager is not an instance of the * class of {@code manager} * @deprecated use {@link #registerKeyManager(KeyManager<P>, boolean)} */ @Deprecated public static synchronized <P> void registerKeyManager( String typeUrl, final KeyManager<P> manager, boolean newKeyAllowed) throws GeneralSecurityException { if (manager == null) { throw new IllegalArgumentException("key manager must be non-null."); } if (!typeUrl.equals(manager.getKeyType())) { throw new GeneralSecurityException("Manager does not support key type " + typeUrl + "."); } registerKeyManager(manager, newKeyAllowed); }
/** * Tries to register a key manager according to the specification in {@code entry}. * * @throws GeneralSecurityException if cannot register this config with the {@link Registry}. This * usually happens when {@code entry} is already registered or the Registry cannot find any * {@link com.google.crypto.tink.KeyManager} or {@link com.google.crypto.tink.Catalogue} that * can handle the entry. In both cases the error message should show how to resolve it. */ @SuppressWarnings({"rawtypes", "unchecked"}) public static void registerKeyType(KeyTypeEntry entry) throws GeneralSecurityException { validate(entry); Catalogue catalogue = Registry.getCatalogue(entry.getCatalogueName()); KeyManager keyManager = catalogue.getKeyManager( entry.getTypeUrl(), entry.getPrimitiveName(), entry.getKeyManagerVersion()); Registry.registerKeyManager(keyManager, entry.getNewKeyAllowed()); }