Error: concatUint8Array: Data must be in the form of a Uint8Array

Solution 1:

I was getting the same issue and then I had to use a specific openpgp version. This is what ended up working for me:

"openpgp": "4.10.10",
"text-encoding-utf-8": "^1.0.2",

So, I had to use the proper functions inherent to this openpgp version as follows:

test('Encrypts a file using the GPG file', async () => {
    const textEncoding = await import("text-encoding-utf-8")
    global.TextEncoder = textEncoding.TextEncoder
    global.TextDecoder = textEncoding.TextDecoder


    const publicKey = fs.readFileSync('/path/file.asc')

    const input = fs.createReadStream('a.txt')

    const encrypted = await openpgp.encrypt({
        message: await openpgp.message.fromBinary(input),
        publicKeys: (await openpgp.key.readArmored(publicKey)).keys,
    })
    console.log(encrypted)

Let me know if it works for you