Baseline Widely available *
å®å ¨ãªã³ã³ããã¹ãç¨: ãã®æ©è½ã¯ä¸é¨ã¾ãã¯ãã¹ã¦ã®å¯¾å¿ãã¦ãããã©ã¦ã¶ã¼ã«ããã¦ãå®å ¨ãªã³ã³ããã¹ã (HTTPS) ã§ã®ã¿å©ç¨ã§ãã¾ãã
exportKey()
㯠SubtleCrypto
ã¤ã³ã¿ã¼ãã§ã¤ã¹ã®ã¡ã½ããã§ããã¼ãã¨ã¯ã¹ãã¼ããã¾ããããªãã¡ããã㯠CryptoKey
ãªãã¸ã§ã¯ããå
¥åã¨ãã¦åãããã®éµãå¤é¨ã®ãã¼ã¿ãã«ãªå½¢å¼ã§è¡¨ãã¾ãã
éµãã¨ã¯ã¹ãã¼ãããã«ã¯ããã®éµã® CryptoKey.extractable
ã true
ã«è¨å®ãã¦ããå¿
è¦ãããã¾ãã
éµã¯ããã¤ãã®æ¸å¼ã§ã¨ã¯ã¹ãã¼ããããã¨ãã§ãã¾ãã詳細㯠SubtleCrypto.importKey()
ãã¼ã¸ã®å¯¾å¿ããå½¢å¼ãåç
§ãã¦ãã ããã
éµã¯æå·åãããå½¢å¼ã§ã¯ã¨ã¯ã¹ãã¼ãããã¾ãããéµãã¨ã¯ã¹ãã¼ãããéã«æå·åããã«ã¯ã代ããã« SubtleCrypto.wrapKey()
API ã使ç¨ãã¦ãã ããã
format
ãã¼ãã¨ã¯ã¹ãã¼ããããã¼ã¿å½¢å¼ã表ãæååå¤ã以ä¸ã®ãããããæå®ãã¾ãã
raw
: Raw å½¢å¼ãpkcs8
: PKCS #8 å½¢å¼ãspki
: SubjectPublicKeyInfo å½¢å¼ãjwk
: JSON Web Key å½¢å¼ãkey
ã¨ã¯ã¹ãã¼ããã CryptoKey
ã
ãããã¹ (Promise
) ã§ãã
format
ã jwk
ã§ãã£ãå ´åããããã¹ã¯ãã¼ãå«ã JSON ãªãã¸ã§ã¯ãã§å±¥è¡ããã¾ããArrayBuffer
ã§ãããã¹ãå±¥è¡ããã¾ãã以ä¸ã®ä¾å¤ãçºçããå ´åããããã¹ã¯æå¦ããã¾ãã
InvalidAccessError
DOMException
æ½åºä¸å¯è½ãªãã¼ãã¨ã¯ã¹ãã¼ããããã¨ããã¨ãã«çºçãã¾ãã
NotSupported
DOMException
䏿ãªå½¢å¼ã§ã¨ã¯ã¹ãã¼ããããã¨ããã¨ãã«çºçãã¾ãã
TypeError
ç¡å¹ãªæ¸å¼ã使ç¨ãããã¨ããã¨ãã«æ´¾çãã¾ãã
ã¡ã¢: GitHub ä¸ã®åä½ä¾ã試ããã¨ãã§ãã¾ãã
Raw ã¨ã¯ã¹ãã¼ããã®ä¾ã§ã¯ãAES éµããéµã®ãã¤ããæ ¼ç´ãã ArrayBuffer
ã¨ãã¦ã¨ã¯ã¹ãã¼ããã¾ããå®å
¨ãªã³ã¼ã㯠GitHub ã§åç
§ãã¦ãã ããã
/*
Export the given key and write it into the "exported-key" space.
*/
async function exportCryptoKey(key) {
const exported = await window.crypto.subtle.exportKey("raw", key);
const exportedKeyBuffer = new Uint8Array(exported);
const exportKeyOutput = document.querySelector(".exported-key");
exportKeyOutput.textContent = `[${exportedKeyBuffer}]`;
}
/*
Generate an encrypt/decrypt secret key,
then set up an event listener on the "Export" button.
*/
window.crypto.subtle
.generateKey(
{
name: "AES-GCM",
length: 256,
},
true,
["encrypt", "decrypt"],
)
.then((key) => {
const exportButton = document.querySelector(".raw");
exportButton.addEventListener("click", () => {
exportCryptoKey(key);
});
});
PKCS #8 ã¨ã¯ã¹ãã¼ã
ãã®ä¾ã§ã¯ã RSA ç§å¯ç½²åéµã PKCS #8 ãªãã¸ã§ã¯ãã¨ãã¦ã¨ã¯ã¹ãã¼ããã¾ããã¨ã¯ã¹ãã¼ããããéµã¯ PEM ã¨ã³ã³ã¼ãããã¾ããå®å ¨ãªã³ã¼ã㯠GitHub ã§åç §ãã¦ãã ããã
/*
Convert an ArrayBuffer into a string
from https://developer.chrome.com/blog/how-to-convert-arraybuffer-to-and-from-string/
*/
function ab2str(buf) {
return String.fromCharCode.apply(null, new Uint8Array(buf));
}
/*
Export the given key and write it into the "exported-key" space.
*/
async function exportCryptoKey(key) {
const exported = await window.crypto.subtle.exportKey("pkcs8", key);
const exportedAsString = ab2str(exported);
const exportedAsBase64 = window.btoa(exportedAsString);
const pemExported = `-----BEGIN PRIVATE KEY-----\n${exportedAsBase64}\n-----END PRIVATE KEY-----`;
const exportKeyOutput = document.querySelector(".exported-key");
exportKeyOutput.textContent = pemExported;
}
/*
Generate a sign/verify key pair,
then set up an event listener on the "Export" button.
*/
window.crypto.subtle
.generateKey(
{
name: "RSA-PSS",
// Consider using a 4096-bit key for systems that require long-term security
modulusLength: 2048,
publicExponent: new Uint8Array([1, 0, 1]),
hash: "SHA-256",
},
true,
["sign", "verify"],
)
.then((keyPair) => {
const exportButton = document.querySelector(".pkcs8");
exportButton.addEventListener("click", () => {
exportCryptoKey(keyPair.privateKey);
});
});
SubjectPublicKeyInfo ã¨ã¯ã¹ãã¼ã
ãã®ä¾ã¯ãRSA å ¬éæå·åéµã PEM ã¨ã³ã³ã¼ãããã SubjectPublicKeyInfo ãªãã¸ã§ã¯ãã¨ãã¦ã¨ã¯ã¹ãã¼ããã¾ããå®å ¨ãªã³ã¼ã㯠GitHub ã§åç §ãã¦ãã ãã.
/*
Convert an ArrayBuffer into a string
from https://developer.chrome.com/blog/how-to-convert-arraybuffer-to-and-from-string/
*/
function ab2str(buf) {
return String.fromCharCode.apply(null, new Uint8Array(buf));
}
/*
Export the given key and write it into the "exported-key" space.
*/
async function exportCryptoKey(key) {
const exported = await window.crypto.subtle.exportKey("spki", key);
const exportedAsString = ab2str(exported);
const exportedAsBase64 = window.btoa(exportedAsString);
const pemExported = `-----BEGIN PUBLIC KEY-----\n${exportedAsBase64}\n-----END PUBLIC KEY-----`;
const exportKeyOutput = document.querySelector(".exported-key");
exportKeyOutput.textContent = pemExported;
}
/*
Generate an encrypt/decrypt key pair,
then set up an event listener on the "Export" button.
*/
window.crypto.subtle
.generateKey(
{
name: "RSA-OAEP",
// Consider using a 4096-bit key for systems that require long-term security
modulusLength: 2048,
publicExponent: new Uint8Array([1, 0, 1]),
hash: "SHA-256",
},
true,
["encrypt", "decrypt"],
)
.then((keyPair) => {
const exportButton = document.querySelector(".spki");
exportButton.addEventListener("click", () => {
exportCryptoKey(keyPair.publicKey);
});
});
JSON Web Key ã¨ã¯ã¹ãã¼ã
ãã®ä¾ã§ã¯ãECDSA ç§å¯ç½²åéµã JSON ã¦ã§ãéµãªãã¸ã§ã¯ãã¨ãã¦ã¨ã¯ã¹ãã¼ããã¾ããå®å ¨ãªã³ã¼ã㯠GitHub ã§åç §ãã¦ãã ãã.
/*
Export the given key and write it into the "exported-key" space.
*/
async function exportCryptoKey(key) {
const exported = await window.crypto.subtle.exportKey("jwk", key);
const exportKeyOutput = document.querySelector(".exported-key");
exportKeyOutput.textContent = JSON.stringify(exported, null, " ");
}
/*
Generate a sign/verify key pair,
then set up an event listener on the "Export" button.
*/
window.crypto.subtle
.generateKey(
{
name: "ECDSA",
namedCurve: "P-384",
},
true,
["sign", "verify"],
)
.then((keyPair) => {
const exportButton = document.querySelector(".jwk");
exportButton.addEventListener("click", () => {
exportCryptoKey(keyPair.privateKey);
});
});
仿§æ¸ ãã©ã¦ã¶ã¼ã®äºææ§ é¢é£æ
å ±
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4