تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
من الناحية العملية، توفّر Tink Key عنصرًا لتمثيلها.
المفاتيح والكائنات Parameters لتمثيل Parameters.
على سبيل المثال، في Java، لدينا AesGcmKey كائنات
تمثل مفاتيح GCM لمعيار AES.
في هذا القسم، نوضح كيفية تصميم هذه الكائنات في Java وكيف
للتفاعل.
كائنات Parameters
يمكنك استخدام AES GCM، وهو مخطط يُستخدم على نطاق واسع لتشفير AEAD.
يوفّر Tink عنصر AesGcmParameters بالمعلومات اللازمة من أجل
إنشاء AesGcmKey، وهو ما سنشرحه لاحقًا.
يظهر التسلسل الهرمي للمعلمات في Java على النحو التالي:
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(){...}}
كما هو موضّح في القسم
مجموعات المفاتيح، ووضع العلامات على النصوص المُشفَّرة،
هناك متطلبات على رقم التعريف لبعض المفاتيح، عندما تكون في مجموعة مفاتيح. كلّ
يستخدم الكائن Parameters الطريقة hasIdRequirement التي تحدد ما إذا كان قد تم
المفتاح الذي أنشأه هذا الكائن Parameters يتضمن رقم التعريف المطلوب أو لا.
يوفر الكائن AesGcmParameters بعد ذلك الطريقتين getKeySizeBytes()،
getIvSizeBytes()، وgetTagSizeBytes(). تُرجع هذه أطوال
والمفتاح المستخدم وطول المفتاح IV المستخدم وطول العلامة المنتجة،
بالبايت. بينما توفر Tink بعض هذه الدوال لتحقيق الاكتمال، إلا أنها
لا تسمح دائمًا بإنشاء Aead لكل خيار. على سبيل المثال، حاليًا
تتوافق فقط 12 بايت IV مع بروتوكول AES GCM.
يوفّر الكائن AesGcmParameters أيضًا إلغاءات لما سبق
محددة (والطريقتان القياسيتان في Java equals وhashCode)
وهو ما يعتبر ممارسة جيدة).
وأخيرًا، يوفّر طرقًا ثابتة لإنشاء كائنات AeadParameters جديدة.
وهي تتحقق من صحة المدخلات، أي أنها تتحقق من أن الحجم هو واحد من 16 أو 24
أو 32.
العناصر الرئيسية
لدى Tink أيضًا تسلسل هرمي رئيسي. بالإضافة إلى مثالنا عن AES GCM، يبدو
النحو التالي:
تعرض الطريقة getIdRequirementOrNull المعرّف الذي يحتاجه هذا المفتاح،
أو null إذا لم تكن هناك أي متطلبات.
(مثل هذا الشرط على المفتاح يأتي من حقيقة أن Tink في بعض الحالات
بادئات النصوص المُشفَّرة أو التوقيعات بالسلسلة 0x01<id>، يُرجى الاطّلاع على القسم
وضع علامات النص المُشفر).
سيكون هذا دائمًا متسقًا مع نتيجة
getParameters().hasIdRequirement() والقائمون على تنفيذ العناصر الجديدة
والفئات الرئيسية لضمان ذلك.
تتطلب عمليات تنفيذ Key أيضًا توفير طريقة equalsKey
ومقارنة مفاتيح مختلفة. مثل
طريقة ما تكون مفيدة: على سبيل المثال عند اختبار اشتقاق المفتاح، فإن إحداهما
مهتمة بضمان أن التطبيق المتكرر للمشتق ينتج عنه
نفس الكائن الرئيسي. أيضًا، قد ترغب KMS في التحقق مما إذا كان أي من المفاتيح التي
تقدمها للمستخدمين المختلفين (وهو ما يحدث أحيانًا إذا شارك المستخدمون
وقم بتحميلها على نفس KMS عدة مرات). من الجدير بالذكر أننا
عدم تجاوز طريقة Java equals، لأنّ ذلك سيتطلب منا
ولا يمكن إلغاء hashCode، ولا توجد طريقة لتنفيذ hashCode في بيئة آمنة
متوافقة مع equals بدون وضع افتراضات غير مثبَتة.
بعد ذلك، نحتاج إلى طريقة getParameters(). وهذا يتيح للمستخدمين الحصول على
المعلومات الأصلية عن المعلمات المستخدمة لإنشاء المفتاح.
أخيرًا، تستخدم AesGcmKey طريقة getKeyBytes تعرض المادة الأساسية الأولية.
هذه الطرق شائعة جدًا مع الفئات الرئيسية: فهي خاصة بالنوع،
وتوفير إمكانية الوصول إلى المواد الرئيسية الأساسية باستخدام هؤلاء، المستخدمون
من حيث المبدأ، مثلاً وتنفيذ العنصر الأساسي الذي يمثله المفتاح،
أو إنشاء تسلسل للمفتاح لتخزينه على قرص أو إرساله عبر
الشبكة. المفتاح نفسه مسؤول عن حماية المواد الرئيسية من
الوصول غير المصرح به. على سبيل المثال، تتطلب السمة SecretBytes رمز دخول من أجل
في الواقع تقديم المواد
(يُرجى الاطّلاع على التحكم في الوصول).
المفاتيح غير المتماثلة
بالنسبة إلى الأساسيات غير المتماثلة، يستخدم Tink فئتين رئيسيتين، واحدة للخاصة والأخرى
للمفاتيح العامة. بالنسبة إلى المعلمات، يكون من الأكثر ملاءمة استخدام نفس
class (حيث توجد فئة واحدة فقط يمكن استخدامها لإنشاء المفاتيح).
يضم Tink أيضًا واجهة PrivateKey مع
الدالة getPublicKey().
تاريخ التعديل الأخير: 2025-07-25 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 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()`."]]