deno
deno copied to clipboard
Uncaught Error: ASN.1 error: PEM error: PEM Base64 error: invalid Base64 encoding
Describe the bug when using the mineflayer with deno instead of node it resolves in a Error Steps to Reproduce
- Create a script with the contents
import mineflayer from 'npm:mineflayer';
const bot = mineflayer.createBot({
username: 'bot',
host: 'localhost',
version: '1.20.1',
port: '2555',
});
bot.on('inject_allowed', () => {
console.log('Inject allowed');
});
bot.on('login', () => {
console.log('Succesfully logged in!');
});
bot.on('spawn', () => {
console.log('Succesfully spawned in!');
});
- Execute the command
deno run --allow-all index.js
- See error
error: Uncaught Error: ASN.1 error: PEM error: PEM Base64 error: invalid Base64 encoding
at Object.publicEncrypt (ext:deno_node/internal/crypto/cipher.ts:199:14)
at sendEncryptionKeyResponse (file:///C:/Users/aske/AppData/Local/deno/npm/registry.npmjs.org/minecraft-protocol/1.44.0/src/client/encrypt.js:49:52)
at gotSharedSecret (file:///C:/Users/aske/AppData/Local/deno/npm/registry.npmjs.org/minecraft-protocol/1.44.0/src/client/encrypt.js:28:9)
at ext:deno_node/internal/crypto/_randomBytes.ts:42:9
at Object.action (ext:deno_web/02_timers.js:153:11)
at handleTimerMacrotask (ext:deno_web/02_timers.js:67:10)
at eventLoopTick (ext:core/01_core.js:189:21)
Expected behavior
Inject allowed
Succesfully logged in!'
Succesfully spawned in!'
Environment
- OS: Windows 11
- deno version: 1.36.4
- std version: 0.195.0
Is there any update on this problem?
Is there anything i can do inorder to help getting this fixed?
@littledivy please take a look and suggest a solution.
The following code has same problem
import crypto from "node:crypto"
import { Buffer } from "node:buffer"
let publicKey = `XXXX`
let rsaKey = {
key: publicKey,
padding: crypto.constants.RSA_PKCS1_PADDING,
}
let buffer = Buffer.from(toEncrypt, "utf8")
let encrypted = crypto.publicEncrypt(rsaKey, buffer)
error info:
error: Uncaught (in promise) Error: ASN.1 error: PEM error: PEM Base64 error: invalid Base64 encoding
let encrypted = crypto.publicEncrypt(rsaKey, buffer)
This is a bug in node-minecraft-protocol package. node-minecraft-protocol
generates PEM of non-standard 65-character lines.
Deno follows the rfc7468 PEM strictly.
Generators MUST wrap the base64-encoded lines so that each line consists of exactly 64 characters except for the final line, which will encode the remainder of the data (within the 64-character line boundary), and they MUST NOT emit extraneous whitespace.
I've opened a PR on the node-minecraft-protocol
repo to fix the generator bug: https://github.com/PrismarineJS/node-minecraft-protocol/pull/1292