我是Angular 2中的一个新手。我试图实现一个登录表单,它在某些加密步骤后发送emailid和密码到服务器。Angular 2:window.crypto.subtle.importKey在'localhost'中工作,但不在'ip'上工作
我已通过使用AES-CTR从实现AES-ECB,
https://github.com/diafygi/webcrypto-examples
我已经使用了 'importKey' 和 '加密' 方法如下,
public deriveAKey(input, encryptKey, cryptoIV) {
var ref: TopDivComponent = this;
console.log('Testing before importKey...');
window.crypto.subtle.importKey(
"raw",
ref.stringToArrayBuffer(encryptKey),
{
name: "AES-CTR",
},
true,
["encrypt"]
).then(function (key) {
console.log('Inside then...');
var newvar = ref.stringToArrayBuffer(cryptoIV);
var encrypt = window.crypto.subtle.encrypt(
{
name: "AES-CTR",
counter: newvar,
length: 128,
},
key,
ref.stringToArrayBuffer(input)
).then(function (encrypted) {
var temp = ref.arrayBufferToString(encrypted);
console.log('Encrypted First: ' + encrypted);
console.log('Temp: ' + temp);
console.log('Key: ' + key);
let fin_encrypted = btoa(temp);
// console.log('Encrypted Snc/d: ' + fin_encrypted);
ref.response(fin_encrypted);
// console.log('From deriveKey: ' + fin_encrypted);
});
});
}
我使用本地服务器来获取响应。使用本地主机时一切正常。请求和响应从服务器正确发送和获取。但是,通过IP连接时,它显示错误“NotSupportedError:只允许安全的来源”。
当我用铬金丝雀,它表示importKey方法不被识别。所以当我用Chrome对其进行安慰时,控件并没有超越importKey方法。可能是什么问题?