代码之家  ›  专栏  ›  技术社区  ›  Kaushik

角度2:window.crypto.minute。importKey在“localhost”中工作,但在“ip”上不工作

  •  0
  • Kaushik  · 技术社区  · 9 年前

    我是Angular 2的新手。我正在尝试实现一个登录表单,在某些加密步骤之后将emailid和密码发送到服务器。

    我已经通过使用AES-CTR实现了AES-ECB,

    https://github.com/diafygi/webcrypto-examples

    导入密钥 '和' 加密 "方法如下:,

    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);
            });
        });
    }
    

    NotSupportedError:只允许安全来源 .

    当我使用 铬金丝雀

    1 回复  |  直到 9 年前
        1
  •  2
  •   pedrofb    9 年前

    Chrome限制了WebCryptographyApi的使用,以确保来源安全。它的意思是“https”。 localhost