PeculiarVentures / webcrypto-liner

webcrypto-liner is a polyfill that let's down-level User Agents (like IE/Edge) use libraries that depend on WebCrypto. (Keywords: Javascript, WebCrypto, Shim, Polyfill)
MIT License
149 stars 26 forks source link

Can not call "importKey" for AES-ECB algorithm #41

Closed YuryStrozhevsky closed 6 years ago

rmhrisk commented 6 years ago

@YuryStrozhevsky can you provide more detail?

@microshine please investigate

rmhrisk commented 6 years ago

Sounds like there is no importKey() implemented, @microshine please resolve ASAP.

microshine commented 6 years ago

@YuryStrozhevsky Could you provide more detail?

This code works

//@ts-check
var alg = {
    name: "AES-ECB",
    length: 256,
};
var format = "raw";
crypto.subtle.generateKey(alg, true, ["encrypt", "decrypt"])
    .then((key) => {
        console.log(key.key);
        return crypto.subtle.exportKey(format, key)
    })
    .then((raw) => {
        return crypto.subtle.importKey(format, raw, alg, true, ["encrypt", "decrypt"]);
    })
    .then((key) => {
        console.log(key.key);
    });

image

YuryStrozhevsky commented 6 years ago

@microshine This code does not work:

crypto.importKey("raw",key, { name: "AES-ECB" }, false, ["decrypt"])

Saying

WebCrypto: native 'importKey' for AES-ECB doesn't work. Algorithm: Unrecognized name
microshine commented 6 years ago

I tried

crypto.subtle.importKey("raw",key, { name: "AES-ECB" }, false, ["decrypt"])
crypto.subtle.importKey("raw",key, "AES-ECB", false, ["decrypt"])
crypto.subtle.importKey("raw",key, "aes-ecb", false, ["decrypt"])

image

YuryStrozhevsky commented 6 years ago

@microshine I did not understand your last comment: it is confirming my problem or your are saying I done something wrong?

microshine commented 6 years ago

@YuryStrozhevsky I don't have error on crypto.subtle.importKey. Send me all incoming params to reproduce this error

YuryStrozhevsky commented 6 years ago

@microshine Hmm, I can see on your screenshot exactly the same message:

WebCrypto: native 'importKey' for AES-ECB doesn't work. Algorithm: Unrecognized name
microshine commented 6 years ago

This is warning for native crypto usage

YuryStrozhevsky commented 6 years ago

@microshine So how to fix it?

microshine commented 6 years ago

Do you want to remove this log?

YuryStrozhevsky commented 6 years ago

@microshine So this is not an error but warning? And the key imported successfully?

microshine commented 6 years ago

yes

YuryStrozhevsky commented 6 years ago

@microshine OK, then I close this issue. Instead I need a solution for this issue: before I thought my code is not working because of import but seems it is because of "padding issue".