私はCordovaとforge libraryとブラウザのWeb Crypto APIと協力して、signとimportKeyの操作を実行しています。それにもかかわらず、AndroidデバイスのWeb Crypto APIはcrypto.getRandomValues()しか提供せず、SubtleCryptoは未定義です(cryptotletle)。だから、Web Crypto API shrimとその依存関係Promizを追加すると、この参照が欠けていると修正されると思ったが、何も変わっていない。どんな考えですか?Web Crypto API cryptotletleはApache Cordovaで定義されていません
Chromeでのデバッグ52.0.2743.116では、完全なWeb暗号化APIが提供されていますが、Android搭載デバイスではChromeバージョン52.0.2743.98(Android 4.4.4)が搭載されています。 Web APIはcrypto.getRandomValues()にのみ制限されます。
I'amは基本的にHow to load a PKCS#12 Digital Certificate with Javascript WebCrypto API
コード例から答えを書き換える:index.htmlをインサイド
のJavaScriptファイル
//working with forge without issue
var pkcs12Der = forge.util.decode64(pk);
var pkcs12Asn1 = forge.asn1.fromDer(pkcs12Der);
var pkcs12 = forge.pkcs12.pkcs12FromAsn1(pkcs12Asn1, false, "password");
console.log(pkcs12);
privateKey = null;
// load keypair and cert chain from safe content(s)
for (var sci = 0; sci < pkcs12.safeContents.length; ++sci) {
var safeContents = pkcs12.safeContents[sci];
for (var sbi = 0; sbi < safeContents.safeBags.length; ++sbi) {
var safeBag = safeContents.safeBags[sbi];
// this bag has a private key
if (safeBag.type === forge.pki.oids.keyBag) {
//Found plain private key
privateKey = safeBag.key;
} else if (safeBag.type === forge.pki.oids.pkcs8ShroudedKeyBag) {
// found encrypted private key
privateKey = safeBag.key;
} else if (safeBag.type === forge.pki.oids.certBag) {
// this bag has a certificate...
}
}
}
//function for importingKey
function _importCryptoKeyPkcs8(privateKey, extractable) {
var privateKeyInfoDerBuff = _privateKeyToPkcs8(privateKey);
//import key will not work due to missing reference crypto.subtle
return window.crypto.subtle.importKey(
'pkcs8',
privateKeyInfoDerBuff, {
name: "RSASSA-PKCS1-v1_5",
hash: {
name: "SHA-256"
}
},
extractable, ["sign"]);
}
_importCryptoKeyPkcs8(privateKey, true).
then(function(cryptoKey) {
//sign will not work due to missing reference crypto.subtle
window.crypto.subtle.sign({
name: "RSASSA-PKCS1-v1_5"
},
cryptoKey,
digestToSignBuf)
.then(function(signature2) {
});
});
サンプルコードを表示できますか?特にwebcrypto-shimライブラリの場合 – e666
@ e666コードサンプルを追加しました。定義されていないwindow.crypto.subtleを正しく参照することができません。 – Marek
これを完全に行うことはできませんか?あなたは 'window.crypto'をまったく必要としていますか? –