Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

272
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda