此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

AuthenticatorAttestationResponse:getPublicKey() 方法

Baseline 2023
Newly available

Since ⁨October 2023⁩, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

安全上下文: 此特性仅在一些支持的浏览器安全上下文(HTTPS)中可用。

AuthenticatorAttestationResponse 接口的 getPublicKey() 方法返回一个其中包含新凭据的 DER SubjectPublicKeyInfo(参见主体公钥信息)的 ArrayBuffer。当不可用时将返回 null

这是一个用于方便地访问公钥的便捷函数。此密钥需要存储起来,以便验证将来的身份验证操作(例如使用 navigator.credentials.get())。

语法

js
getPublicKey()

参数

无。

返回值

包含新凭据的 DER SubjectPublicKeyInfo(参见主体公钥信息)的 ArrayBuffer,当不可用时返回 null

示例

参见创建公钥凭据以获取详细示例。

规范

Specification
Web Authentication: An API for accessing Public Key Credentials - Level 3
# dom-authenticatorattestationresponse-getpublickey

浏览器兼容性