Recibo el siguiente error cuando intento envolver una clave RSA-PSS usando AES-KW:
The AES-KW input data length is invalid: not a multiple of 8 bytesSin embargo, a veces funciona, pero solo cuando la longitud de la salida de la clave en formato 'pkcs8' es divisible por 8. Quizás eso también se indique en https://developer.mozilla.org/en-US/docs/Web/ API/SubtleCrypto/wrapKey .
Entonces mi pregunta es: ¿No es posible envolver una clave RSA-PSS usando AES-KW? No puedo encontrar ninguna opción de relleno. Si no, ¿es mi mejor opción ir por la ruta IV?
Vea el siguiente código:
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 }; }