Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

266
Visualizações
How to use crypto.subtle.wrapKey to wrap an RSA-PSS private key using AES-KW?

I'm getting the following error when trying to wrap an RSA-PSS key using AES-KW:

The AES-KW input data length is invalid: not a multiple of 8 bytes

It works sometimes though, but only when the length of the output of the key in 'pkcs8' format is divisible by 8. That is perhaps also stated in https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/wrapKey.

My question then is: Is it not possible to wrap an RSA-PSS key using AES-KW? I can't find any padding option. If not, is my best option to go the IV route?

See below code:

export async function wrapKeyAsync(key: CryptoKey, password: string) {

    let keyMaterial = await crypto.subtle.importKey(
        "raw",
        new TextEncoder().encode(password),
        { name: "PBKDF2" },
        false,
        ["deriveBits", "deriveKey"]
    );

    let salt = crypto.getRandomValues(new Uint8Array(16));

    let wrappingKey = await crypto.subtle.deriveKey(
        {
            "name": "PBKDF2",
            salt: salt,
            "iterations": 100_000,
            "hash": "SHA-256"
        },
        keyMaterial,
        { "name": "AES-KW", "length": 256 },
        true,
        ["wrapKey", "unwrapKey"]
    );

    console.log((await crypto.subtle.exportKey("pkcs8", key)).byteLength / 8); // Only works when input is divisible by 8

    return {
        wrappedKey: new Uint8Array(await crypto.subtle.wrapKey(
            "pkcs8",
            key,
            wrappingKey,
            "AES-KW"
        )),
        salt
    };
}
about 4 years ago · Santiago Gelvez
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda