静态
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
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
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.
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.
let stdRSACertificate = {
name: "RSASSA-PKCS10-v1_5",
modulusLength: 2048,
publicExponent: new UInt8Array([1, 0, 1]),
hash: "SHA-256"
};
let stdECDSACertificate = {
name: "ECDSA",
namedCurve: "P-256"
};
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.
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]});
});
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. |
候选推荐 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
generateCertificate
|
Chrome 48 | Edge ≤18 | Firefox 22 | IE No |
Opera
43
|
Safari ? | WebView Android 48 | Chrome Android 48 | Firefox Android 44 |
Opera Android
43
|
Safari iOS ? | Samsung Internet Android 6.0 |
完整支持
不支持
兼容性未知
见实现注意事项。
RTCPeerConnection
canTrickleIceCandidates
connectionState
currentLocalDescription
currentRemoteDescription
getDefaultIceServers()
iceConnectionState
iceGatheringState
localDescription
onaddstream
onconnectionstatechange
ondatachannel
onicecandidate
oniceconnectionstatechange
onicegatheringstatechange
onidentityresult
onidpassertionerror
onidpvalidationerror
onnegotiationneeded
onpeeridentity
onremovestream
onsignalingstatechange
ontrack
peerIdentity
pendingLocalDescription
pendingRemoteDescription
remoteDescription
sctp
signalingState
addIceCandidate()
addStream()
addTrack()
close()
createAnswer()
createDataChannel()
createOffer()
generateCertificate() static function
getConfiguration()
getIdentityAssertion()
getReceivers()
getSenders()
getStats()
getStreamById()
getTransceivers()
removeStream()
removeTrack()
restartIce()
setConfiguration()
setIdentityProvider()
setLocalDescription()
setRemoteDescription()
MediaDevices.getUserMedia()
Navigator.mediaDevices
RTCCertificate
RTCDTMFSender
RTCDTMFToneChangeEvent
RTCDataChannel
RTCDataChannelEvent
RTCDtlsTransport
RTCErrorEvent
RTCIceCandidate
RTCIceTransport
RTCPeerConnectionIceErrorEvent
RTCPeerConnectionIceEvent
RTCRtpReceiver
RTCRtpSender
RTCRtpTransceiver
RTCSctpTransport
RTCSessionDescription
RTCStatsReport
RTCTrackEvent