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
PatoOP2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
Pato
PatoOP2y 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;
}
sakuta
sakuta2y ago
@aegisdaemon you also seem to use nodejs' fs module which is not available on workers
Pato
PatoOP2y ago
how else could i read the file? import is not working @boywithkeyboard
sakuta
sakuta2y 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
Want results from more Discord servers?
Add your server