Chữ ký số
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Kiểu dữ liệu Chữ ký số cho phép bạn xác minh rằng không ai can thiệp vào dữ liệu của bạn. Phương thức này đảm bảo tính xác thực và tính toàn vẹn, nhưng không đảm bảo tính bảo mật của dữ liệu đã ký. Phương thức này là bất đối xứng, nghĩa là sử dụng một cặp khoá (khoá công khai và khoá riêng tư).
Kiểu gốc Chữ ký số có các thuộc tính sau:
- Tính xác thực: Không thể tạo chữ ký mà
PublicKeyVerify.Verify(signature, message)
xác thực, trừ phi bạn có khoá riêng tư.
- Bất đối xứng: Quá trình tạo chữ ký sử dụng một khoá khác với khoá xác minh chữ ký. Nhờ đó, bạn có thể phân phối khoá công khai để xác minh chữ ký cho các bên không thể tự tạo chữ ký.
Nếu không cần tính không đối xứng, hãy cân nhắc sử dụng nguyên hàm MAC đơn giản và hiệu quả hơn.
Chức năng của chữ ký số được biểu thị trong Tink dưới dạng một cặp nguyên hàm:
- PublicKeySign để ký dữ liệu
- PublicKeyVerify để xác minh chữ ký
Chọn loại khoá
Bạn nên sử dụng ECDSA_P256 cho hầu hết các trường hợp sử dụng, nhưng có nhiều tuỳ chọn. Nói chung, những điều sau đây là đúng:
- ECDSA_P256 là tuỳ chọn được sử dụng rộng rãi nhất và là tuỳ chọn mặc định hợp lý. Tuy nhiên, xin lưu ý rằng chữ ký ECDSA là có thể bị thay đổi.
- ED25519 tạo chữ ký xác định và mang lại hiệu suất tốt hơn so với ECDSA_P256.
- RSA_SSA_PKCS1_3072_SHA256_F4 tạo chữ ký xác định và mang lại hiệu suất xác minh tốt nhất (nhưng việc ký chậm hơn nhiều so với ECDSA_P256 hoặc ED25519).
Cam kết bảo mật tối thiểu
- Dữ liệu cần ký có thể có độ dài tuỳ ý
- Cấp độ bảo mật 128 bit chống lại các cuộc tấn công thông báo được chọn thích ứng cho các giao thức dựa trên đường cong elip
- Mức bảo mật 112 bit chống lại các cuộc tấn công thông báo được chọn thích ứng cho các giao thức dựa trên RSA (cho phép khoá 2048 bit)
Tính dễ uốn
Một giao thức chữ ký có thể bị làm giả nếu kẻ tấn công có thể tạo một chữ ký hợp lệ khác cho một thông báo đã được ký. Mặc dù đây không phải là vấn đề đối với hầu hết các trường hợp, nhưng trong một số trường hợp, lập trình viên ngầm giả định rằng chữ ký hợp lệ là duy nhất và điều này có thể dẫn đến kết quả không mong muốn.
Trường hợp sử dụng mẫu
Xem bài viết Tôi muốn ký dữ liệu bằng chữ ký số.
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-25 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-25 UTC."],[[["\u003cp\u003eDigital signatures ensure data integrity and authenticity by verifying that data hasn't been tampered with.\u003c/p\u003e\n"],["\u003cp\u003eThey use a pair of keys (public and private) for asymmetric signing and verification, allowing for secure distribution of the public key.\u003c/p\u003e\n"],["\u003cp\u003eTink provides two primitives for digital signatures: \u003ccode\u003ePublicKeySign\u003c/code\u003e for signing and \u003ccode\u003ePublicKeyVerify\u003c/code\u003e for verifying.\u003c/p\u003e\n"],["\u003cp\u003eECDSA_P256 is generally recommended, with ED25519 offering better performance and RSA_SSA_PKCS1_3072_SHA256_F4 providing the fastest verification.\u003c/p\u003e\n"],["\u003cp\u003eDigital signatures in Tink guarantee a minimum of 112-bit security and support data of any length.\u003c/p\u003e\n"]]],["Digital signatures ensure data authenticity and integrity using asymmetric key pairs (public and private). `PublicKeySign` signs data, while `PublicKeyVerify` checks signatures. Key options include the widely used ECDSA_P256, faster ED25519, and high-verification-performance RSA_SSA_PKCS1_3072_SHA256_F4. Signatures offer 128-bit security (elliptic curves) or 112-bit security (RSA). ECDSA signatures are malleable, allowing attackers to forge valid signatures. If asymmetry is not needed consider using MAC.\n"],null,["# Digital Signature\n\nThe Digital Signature primitive lets you verify that no one has tampered with\nyour data. It provides authenticity and integrity, but not secrecy, of the\nsigned data. It is asymmetric, meaning it uses a pair of keys (public key and\nprivate key).\n\nThe Digital Signature primitive has the following properties:\n\n- **Authenticity** : It is impossible to create a signature for which `PublicKeyVerify.Verify(signature, message)` validates, unless you have the private key.\n- **Asymmetric**: Creating the signature uses a different key than verifying it. This lets you distribute the public key to verify signatures to parties that can't create signatures themselves.\n\nIf you don't need asymmetry, consider using the simpler and more efficient\n[MAC](/tink/mac) primitive instead.\n\nThe functionality of digital signatures is represented in Tink as a pair of\nprimitives:\n\n- *PublicKeySign* for signing data\n- *PublicKeyVerify* for verifying the signature\n\n### Choose a key type\n\nWe recommend using **ECDSA_P256** for most use cases, but there are a variety of\noptions. In general, the following holds true:\n\n- ECDSA_P256 is the most widely used option and a reasonable default. Note though that ECDSA signatures are [malleable](#malleable).\n- ED25519 creates deterministic signatures and provides better performance than ECDSA_P256.\n- RSA_SSA_PKCS1_3072_SHA256_F4 creates deterministic signatures and provides the best verification performance (but signing is much slower than ECDSA_P256 or ED25519).\n\n### Minimal security guarantees\n\n- Data to be signed can have arbitrary length\n- 128-bit security level against adaptive chosen-message attacks for elliptic curve based schemes\n- 112-bit security level against adaptive chosen-message attacks for RSA based schemes (allows 2048-bit keys)\n\n### Malleability\n\nA signature scheme is malleable if an attacker can create a different valid\nsignature for an already signed message. While this is not a problem for most\nscenarios, in some cases programmers implicitly assume that valid signatures are\nunique, and this can lead to unexpected results.\n\n### Example use case\n\nSee I want to [digitally sign data](/tink/digitally-sign-data)."]]