publicabstractclassParameters{publicabstractbooleanhasIdRequirement();}publicabstractclassAeadParametersextendsParameters{}publicfinalclassAesGcmParametersextendsAeadParameters{/** * The Variant specified how ciphertexts are [tagged](/tink/design/keysets#tagging_ciphertexts). */publicstaticfinalclassVariant{...}/** A helper object to create new AesGcmParameters. */publicstaticfinalclassBuilder{...}publicintgetKeySizeBytes(){...}publicintgetIvSizeBytes(){...}publicintgetTagSizeBytes(){...}publicVariantgetVariant(){...}publicOutputPrefixTypegetOutputPrefixType(){...}publicbooleanequals(Objectobject){...}publicinthashCode(){...}}
[null,null,["最后更新时间 (UTC):2025-07-25。"],[[["\u003cp\u003eTink uses \u003ccode\u003eKey\u003c/code\u003e objects to represent keys and \u003ccode\u003eParameters\u003c/code\u003e objects to represent parameters, organizing them in class hierarchies for different cryptographic primitives like AES GCM.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eParameters\u003c/code\u003e objects contain information like key size, IV size, tag size, and whether the key requires an ID; they are used to create corresponding \u003ccode\u003eKey\u003c/code\u003e objects.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eKey\u003c/code\u003e objects provide access to key material, parameters, and ID requirements, with methods like \u003ccode\u003egetKeyBytes\u003c/code\u003e and \u003ccode\u003egetParameters\u003c/code\u003e ensuring secure access and key management.\u003c/p\u003e\n"],["\u003cp\u003eAsymmetric primitives utilize separate key classes for private and public keys, with a \u003ccode\u003ePrivateKey\u003c/code\u003e interface including a \u003ccode\u003egetPublicKey()\u003c/code\u003e function for key pair management.\u003c/p\u003e\n"],["\u003cp\u003eKey equality is checked using \u003ccode\u003eequalsKey\u003c/code\u003e rather than overriding Java's \u003ccode\u003eequals\u003c/code\u003e method to avoid potential security issues related to hash code implementation and key comparisons.\u003c/p\u003e\n"]]],["Tink utilizes `Key` objects for keys and `Parameters` objects for configuration. `AesGcmParameters` specifies AES GCM parameters like key, IV, and tag sizes and whether an ID is required. `AesGcmKey` implements `AeadKey`, providing methods for accessing raw key material (`getKeyBytes`), associated parameters, and any required ID. Key classes also implement `equalsKey` to compare keys and `getParameters` to retrieve parameter information. Asymmetric primitives employ distinct private and public key classes with shared `Parameters` and a `getPublicKey` method on `PrivateKey`.\n"],null,["# Key and Parameters Objects\n\n| This section describes the future design of Tink. The current status may depend on the programming language used.\n\nIn practice, Tink provides `Key` objects to represent\n[keys](/tink/design/keys) and `Parameters` objects to represent `Parameters`.\nFor example, in Java, we have `AesGcmKey` objects to\nrepresent AES GCM keys.\n\nIn this section, we explain how these objects are designed in Java and how they\ninteract.\n\n`Parameters` objects\n--------------------\n\nConsider AES GCM, a widely used AEAD encryption scheme.\nTink provides an `AesGcmParameters` object with the necessary information to\ncreate a `AesGcmKey`, which we explain later.\nThe parameters hierarchy in Java looks as follows: \n\n public abstract class Parameters {\n public abstract boolean hasIdRequirement();\n }\n\n public abstract class AeadParameters extends Parameters {}\n\n public final class AesGcmParameters extends AeadParameters {\n /**\n * The Variant specified how ciphertexts are [tagged](/tink/design/keysets#tagging_ciphertexts).\n */\n public static final class Variant {...}\n /** A helper object to create new AesGcmParameters. */\n public static final class Builder {...}\n\n public int getKeySizeBytes() {...}\n public int getIvSizeBytes() {...}\n public int getTagSizeBytes() {...}\n\n public Variant getVariant() {...}\n\n public OutputPrefixType getOutputPrefixType() {...}\n public boolean equals(Object object) {...}\n public int hashCode() {...}\n }\n\nAs explained in the section\n[Keysets, Tagging Ciphertexts](/tink/design/keysets#tagging_ciphertexts),\nsome keys have a requirement on their id, when they are in a keyset. Every\n`Parameters` object has a method `hasIdRequirement` which specifies whether the\nkey created by this `Parameters` object will have such a required id, or not.\n\nThe `AesGcmParameters` object next provides methods `getKeySizeBytes()`,\n`getIvSizeBytes()`, and `getTagSizeBytes()`. These return the lengths of\nthe key used, the length of the IV used, and the length of the produced tag,\nin bytes. While Tink provides some of these functions for completeness, it\ndoes not always allow creating `Aead`s for every choice. For example, currently\nonly 12 byte IVs are supported for AES GCM.\n\nThe `AesGcmParameters` object also provides overrides for the previously\ndefined methods (and the Java standard methods `equals` and `hashCode`\nwhich is considered good practice).\n\nFinally, it provides static methods to create new `AeadParameters` objects.\nThese validate the inputs, i.e., they check that the size is one of 16, 24,\nor 32.\n\nKey objects\n-----------\n\nTink also has a key hierarchy. Remaining with our example of AES GCM, it looks\nlike this: \n\n public abstract class Key {\n public abstract Parameters getParameters();\n public abstract @Nullable Integer getIdRequirementOrNull();\n public abstract boolean equalsKey(Key other);\n }\n\n public abstract class AeadKey extends Key {\n public abstract AeadParameters getParameters();\n public abstract Bytes getOutputPrefix();\n }\n\n public final class AesGcmKey implements AeadKey {\n public SecretBytes getKeyBytes();\n public abstract Bytes getOutputPrefix();\n public AesGcmParameters getParameters();\n public @Nullable Integer getIdRequirementOrNull();\n public boolean equalsKey(Key object);\n }\n\nThe method `getIdRequirementOrNull` returns the id which this key needs to have,\nor `null` if there is no requirement.\n(Such a requirement on the key comes from the fact that Tink in some cases\nprefixes ciphertexts or signatures with the string `0x01\u003cid\u003e`, see the section\non [ciphertext tagging](/tink/design/keysets#tagging_ciphertexts)).\n\nThis will always be consistent with the result of\n`getParameters().hasIdRequirement()` and implementers of new\nkey classes need to ensure this.\n\nImplementations of `Key` also need to provide a method `equalsKey` to\ncompare different keys. Such\na method is often useful: for example when testing key derivation, one is\ninterested in ensuring that repeated application of the derivation yields\nthe same key object. Also, a KMS might want to check if any of the keys it\nprovides to different users are equal (which happens sometimes if users share\nkeys and upload them to the same KMS multiple times). It is notable that we\ndo not override the Java method `equals`, because this would require us to\noverride `hashCode`, and there is no way to implement `hashCode` in a safe\nway compatible with `equals` without making unproven assumptions.\n\nNext, we require a method `getParameters()`. This allows users to get the\noriginal information about the Parameters used to create the key.\n\nFinally, `AesGcmKey` has a method `getKeyBytes` which returns the raw key material.\nSuch methods are very typical for key classes: they are specific to the type,\nand provide access to the underlying key material. Using those, users\ncan in principle e.g. implement the primitive represented by the key,\nor serialize the key in order to store it on disk or send it over the\nnetwork. The key itself is responsible for protecting the key material against\nunauthorized access. For example, `SecretBytes` requires an access token to\nactually provide the material\n(see [Access Control](/tink/design/access_control)).\n\nAsymmetric Keys\n---------------\n\nFor asymmetric primitives, Tink uses two Key classes, one for private and one\nfor public keys. For the Parameters, it is more convenient to use the same\nclass (as there is only one class which can be used to generate the keys).\n\nTink also has an interface `PrivateKey` with the additional\nfunction `getPublicKey()`."]]