静态 RTCPeerConnection.generateCertificate() function creates an X.509 certificate and corresponding private key, returning a promise that resolves with the new RTCCertificate once it's generated.

句法

let certPromise = RTCPeerConnection.generateCertificate(keygenAlgorithm)
					

参数

keygenAlgorithm
A Web 加密 API AlgorithmIdentifier string or an Algorithm -subclassed object specifying an algorithm to use when creating the certificate's key.

RTCPeerConnection.generateCertificate() is a static method, so it is always called on the RTCPeerConnection interface itself, not an instance thereof.

返回值

A promise which resolves to a new RTCCertificate object containing a new key based on the specified options.

异常

NotSupportedError
The normalized form of keygenAlgorithm specifies an algorithm or algorithm settings that the browser doesn't support, or which it does not allow for use with an RTCPeerConnection .

Other errors may occur; for example, if the specified keygenAlgorithm can't be successfully converted into an RTCCertificateExpiration dictionary, the error that occurs during that conversion will be thrown.

描述

If a string is specified, it must be a Web 加密 API -compatible algorithm name string. Alternatively, you can provide specific details for the algorithm's configuration by providing an object based on one of the Web Crypto API's Algorithm class's subclasses.

Standard configurations

All browsers are required to support the following two configurations. It's entirely possible that a browser's default settings may be different, but these are always supported.

RSASSA-PKCS1-v1_5

let stdRSACertificate = {
  name: "RSASSA-PKCS10-v1_5",
  modulusLength: 2048,
  publicExponent: new UInt8Array([1, 0, 1]),
  hash: "SHA-256"
};
					

ECDSA

let stdECDSACertificate = {
  name: "ECDSA",
  namedCurve: "P-256"
};
					

Certificate expiration time

By default the new certificate is configured with expires set to a DOMTimeStamp value of 2592000000, or 30 days. The expiration time cannot exceed 31536000000, or 365 days. It's also useful to note that browsers may further restrict the expiration time of certificates if they choose.

范例

Specifying algorithm details

This example requests a new RSASSA-PKCS1-v1_5 certificate using a SHA-256 hash and a modulus length of 2048.

RTCPeerConnection.generateCertificate({
    name: 'RSASSA-PKCS1-v1_5',
    hash: 'SHA-256',
    modulusLength: 2048,
    publicExponent: new Uint8Array([1, 0, 1])
}).then(function(cert) {
  var pc = new RTCPeerConnection({certificates: [cert]});
});
					

Specifying an algorithm by name

The example below simply specifies a string requesting an ECDSA certificate.

RTCPeerConnection.generateCertificate("ECDSA");
					

规范

规范 状态 注释
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCPeerConnection.generateCertificate()' in that specification.
候选推荐 初始定义。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
generateCertificate Chrome 48 Edge ≤18 Firefox 22 IE No Opera 43
43
Promise-based version.
不支持 37 — 43
Safari ? WebView Android 48 Chrome Android 48 Firefox Android 44 Opera Android 43
43
Promise-based version.
不支持 37 — 43
Safari iOS ? Samsung Internet Android 6.0

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

见实现注意事项。

另请参阅

元数据

  • 最后修改:
  1. WebRTC API
  2. RTCPeerConnection
  3. 构造函数
    1. RTCPeerConnection()
  4. 特性
    1. canTrickleIceCandidates
    2. connectionState
    3. currentLocalDescription
    4. currentRemoteDescription
    5. getDefaultIceServers()
    6. iceConnectionState
    7. iceGatheringState
    8. localDescription
    9. onaddstream
    10. onconnectionstatechange
    11. ondatachannel
    12. onicecandidate
    13. oniceconnectionstatechange
    14. onicegatheringstatechange
    15. onidentityresult
    16. onidpassertionerror
    17. onidpvalidationerror
    18. onnegotiationneeded
    19. onpeeridentity
    20. onremovestream
    21. onsignalingstatechange
    22. ontrack
    23. peerIdentity
    24. pendingLocalDescription
    25. pendingRemoteDescription
    26. remoteDescription
    27. sctp
    28. signalingState
  5. 方法
    1. addIceCandidate()
    2. addStream()
    3. addTrack()
    4. close()
    5. createAnswer()
    6. createDataChannel()
    7. createOffer()
    8. generateCertificate() static function
    9. getConfiguration()
    10. getIdentityAssertion()
    11. getReceivers()
    12. getSenders()
    13. getStats()
    14. getStreamById()
    15. getTransceivers()
    16. removeStream()
    17. removeTrack()
    18. restartIce()
    19. setConfiguration()
    20. setIdentityProvider()
    21. setLocalDescription()
    22. setRemoteDescription()
  6. 事件
    1. addstream
    2. icecandidateerror
    3. identityresult
    4. negotiationneeded
    5. removestream
    6. signalingstatechange
  7. 继承:
    1. EventTarget
  8. Related pages for WebRTC
    1. MediaDevices.getUserMedia()
    2. Navigator.mediaDevices
    3. RTCCertificate
    4. RTCDTMFSender
    5. RTCDTMFToneChangeEvent
    6. RTCDataChannel
    7. RTCDataChannelEvent
    8. RTCDtlsTransport
    9. RTCErrorEvent
    10. RTCIceCandidate
    11. RTCIceTransport
    12. RTCPeerConnectionIceErrorEvent
    13. RTCPeerConnectionIceEvent
    14. RTCRtpReceiver
    15. RTCRtpSender
    16. RTCRtpTransceiver
    17. RTCSctpTransport
    18. RTCSessionDescription
    19. RTCStatsReport
    20. RTCTrackEvent