invisal / god_crypto

Pure Javascript/Typescript Crypto Implementation for Deno. AES, RSA, HMAC, and TOTP
MIT License
93 stars 16 forks source link

rsa_import_pem_private_pkcs8 trimming fails #31

Open ribizli opened 3 years ago

ribizli commented 3 years ago

-----BEGIN PRIVATE KEY----- and -----END PRIVATE KEY----- are 27 + 25 = 52 characters.

But the code truncates 57 characters:

function rsa_import_pem_private_pkcs8(key: string): RSAKeyParams {
  const trimmedKey = key.substr(27, key.length - 57);
}

So I get the error InvalidCharacterError: The string to be decoded is not correctly encoded from atob.

My workaround is to add 5 more - at the end of the file. -----END PRIVATE KEY----------.