How to read a .pem file in a worker

Hey, I was wondering if its possible to read a .pem file in a worker, thanks!
6 Replies
Pato
Pato16mo ago
Can i save it in a R2 bucket or something? I have a .pem file that I need to use to authenticate request to an API So i was wondering how's the best way to storew that key Thanks! One mor thing, does a worker support his module? const crypto = require('crypto'); @skye_31 i see, thanks
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
Pato
Pato16mo ago
can anyone help me to translate this code to webcrypto i cant manage to get it
getSign() {
var sign = crypto.createSign('RSA-SHA256');
sign.update(this.cadenaOriginal);
sign.end();
const key = fs.readFileSync('ssl/key.pem');
let signature_b64 = sign.sign(key, 'base64');
return signature_b64;
}
getSign() {
var sign = crypto.createSign('RSA-SHA256');
sign.update(this.cadenaOriginal);
sign.end();
const key = fs.readFileSync('ssl/key.pem');
let signature_b64 = sign.sign(key, 'base64');
return signature_b64;
}
sk
sk16mo ago
@aegisdaemon you also seem to use nodejs' fs module which is not available on workers
Pato
Pato16mo ago
how else could i read the file? import is not working @boywithkeyboard
sk
sk16mo ago
you could store it in cloudflare's r2 (or any other cdn/storage) and fetch it or you import it directly and bundle it with your code i'd suggest reading https://developers.cloudflare.com/workers/wrangler/bundling