Adding apx.crypto

This commit is contained in:
devpotatoes
2025-07-29 09:36:39 +02:00
parent b6ae865332
commit 19387bcac8
2 changed files with 78 additions and 0 deletions

61
wco/crypto/crypto.js Normal file
View File

@@ -0,0 +1,61 @@
var apx = apx || {};
apx.crypto = apx.crypto || {};
apx.crypto.genKey = async (uuid) => {
return await openpgp.generateKey(
{
type: "ecc",
curve: "curve25519",
userIDs: [
{
alias: uuid
}
],
passphrase: "",
format: "armored",
}
);
};
apx.crypto.encryptMessage = async (message, publicKey) => {
publicKey = await openpgp.readKey(
{
armoredKey: publicKey
}
);
return await openpgp.encrypt(
{
message: await openpgp.createMessage(
{
text: message
}
),
encryptionKeys: publicKey
}
);
};
apx.crypto.decryptMessage = async (encryptedMessage, privateKey) => {
privateKey = await openpgp.readPrivateKey(
{
armoredKey: privateKey
}
);
const message = await openpgp.readMessage(
{
armoredMessage: encryptedMessage
}
);
return await openpgp.decrypt(
{
message,
decryptionKeys: privateKey
}
);
};
export default apx;