I would like to encrypt file saved in Buffer type and return its Base 64 format. This is my code:
encrypt(fileInBuffer: Buffer, publicKey: string): string {
const encrypted = publicEncrypt(publicKey, fileInBuffer)
return encrypted.toString("base64")
}
But i'm getting error when publicEncrypt method is invoking:
Error: error:0409A06E:rsa routines:RSA_padding_add_PKCS1_OAEP_mgf1:data too large for key size
server_1 | at internal/crypto/cipher.js:63:12
I was trying to pass readable stream as a second parameter of this method, but Readable type not passing there. I have to also add (i'm not sure it matters) that i'm not storing file locally, it's saved in memory.