-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdkim.js
34 lines (28 loc) · 869 Bytes
/
dkim.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import crypto from 'crypto';
const genDKIM = async () => {
const rsa = await crypto.subtle.generateKey(
{
name: "RSA-OAEP",
modulusLength: 2048,
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
hash: "SHA-256"
},
true,
["encrypt", "decrypt"]
).catch(e => console.error);
const pem = {
pub: await crypto.subtle.exportKey('spki', rsa.publicKey),
priv: await crypto.subtle.exportKey('pkcs8', rsa.privateKey),
};
const b64 = {
pub: btoa(String.fromCharCode.apply(null, new Uint8Array(pem.pub))),
priv: btoa(String.fromCharCode.apply(null, new Uint8Array(pem.priv))),
};
const dns = `v=DKIM1;p=${b64.pub}`;
return { ...rsa, pem, b64, dns };
};
const { dns, b64 } = await genDKIM();
console.log(JSON.stringify({
dns,
privateKey: b64.priv,
}, null, ' '));