Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const generateKeys4096Demo = async () => {
console.log('generateKeys4096Demo')
const keys = await RSA.generateKeys(4096)
console.log('4096 private:', keys.private) // the private key
console.log('4096 public:', keys.public) // the public key
const encodedMessage = await RSA.encrypt('4096', keys.public)
console.log('4096 encoded message:', encodedMessage)
const message = await RSA.decrypt(encodedMessage, keys.private)
console.log('4096 decoded message:', message);
}
const generateDemo = async () => {
console.log('generateDemo')
const keys = await RSA.generate()
console.log('private:', keys.private) // the private key
console.log('public:', keys.public) // the public key
const encodedMessage = await RSA.encrypt('1234', keys.public)
console.log('encoded message:', encodedMessage)
const message = await RSA.decrypt(encodedMessage, keys.private)
console.log('decoded message:', message);
}
const generateKeys4096Demo = async () => {
console.log('generateKeys4096Demo')
const keys = await RSA.generateKeys(4096)
console.log('4096 private:', keys.private) // the private key
console.log('4096 public:', keys.public) // the public key
const encodedMessage = await RSA.encrypt('4096', keys.public)
console.log('4096 encoded message:', encodedMessage)
const message = await RSA.decrypt(encodedMessage, keys.private)
console.log('4096 decoded message:', message);
}
const generateDemo = async () => {
console.log('generateDemo')
const keys = await RSA.generate()
console.log('private:', keys.private) // the private key
console.log('public:', keys.public) // the public key
const encodedMessage = await RSA.encrypt('1234', keys.public)
console.log('encoded message:', encodedMessage)
const message = await RSA.decrypt(encodedMessage, keys.private)
console.log('decoded message:', message);
}
const generateKeys4096Demo = async () => {
console.log('generateKeys4096Demo')
const keys = await RSA.generateKeys(4096)
console.log('4096 private:', keys.private) // the private key
console.log('4096 public:', keys.public) // the public key
const encodedMessage = await RSA.encrypt('4096', keys.public)
console.log('4096 encoded message:', encodedMessage)
const message = await RSA.decrypt(encodedMessage, keys.private)
console.log('4096 decoded message:', message);
}
const signAlgoDemo = async () => {
console.log('signAlgoDemo')
const keys = await RSA.generate()
const signature = await RSA.signWithAlgorithm(secret, keys.private, RSA.SHA256withRSA)
console.log('signature', signature);
const valid = await RSA.verifyWithAlgorithm(signature, secret, keys.public, RSA.SHA256withRSA)
console.log('verified', valid);
}
const signAlgoDemo = async () => {
console.log('signAlgoDemo')
const keys = await RSA.generate()
const signature = await RSA.signWithAlgorithm(secret, keys.private, RSA.SHA256withRSA)
console.log('signature', signature);
const valid = await RSA.verifyWithAlgorithm(signature, secret, keys.public, RSA.SHA256withRSA)
console.log('verified', valid);
}
d8KnzvRvtlHT1Gu0PH2NWgvrYDQ2lz/fp1huX1/eklhPE1uR8fqxTUeWwyRClQcp
8Ph5joK5/+xQAjO7nSItCBm1AoGAFblYtPET6OjSd9WH2IIZgUcvynHI4CbfMi1T
EMYPml0uekwskJXdXnJtswewjcXtrNTOwTCswg2yZ8EfJMk9wmuB9eIHuJdyxgQz
DNkxJFAwRCyoiF7ABSXEXe9Q69QQ9fBZP0x2YU4gbe3VBVj6J2noWrsfUDVkQ8Zk
9hK2zY0CgYBiMwbP0nafeaB+YO9v2mvwHeCAnFtBsVZkUVp75alsAujr/YEKSKEQ
YiFzbWLAkY7gBrS2b8tbHKXkkYfcWWlpM85ir/uqyNy/6Rb7CPkKUkCInIwZ9Vi2
clP6STevOnNTlyYhNgesy50tSPJEWO6ysC/petudc5t1e1FEM/pBkg==
-----END RSA PRIVATE KEY-----`
const androidEncodedMessage = `Z3iPkJiJCrXLaT11RtwBuSJa4rGbJ7JfDSHMNn/UaLUnGIzFmMT6ZRMtaSmWJhw3pXBES1IqufJB
Wk5vdZuDD7o5AP8i5GHrgVGbf6ix6DIH1+PiJzcfwBcSdEuCMEsustk+tBirK/HuxYt0HQV3B8Sw
EFAFOAPh3y2CsSC7Ibn5Q5cWeDYxfs8XANezs0H3i/X+KZP8owIrKnsERErc0E6bJ/V3tGCoFb+5
m0SibGo5B446iH57hTHf3Sv6GYcThk5+BqP/08VVQ2YXy+oMPng2nVnvzGONdJzfq+9GAKWMx6CE
yiSiGz7AYGDb04FmekL8KqEKy6nTlVERlbwWRg==`
const message = await RSA.decrypt(androidEncodedMessage, androidPkcs1PrivateKey)
console.log('android decoded message:', message);
}
GubRCBGJMBu8qyoNJJLmii8CgYEAtKo7XcTnjlqLJ6z1HJUkLM84vXvXT+aPs1GS
K4yYi2foTW2PM2HJQUWVcH2QJuYefT1pGYNhqFrdN414FzqMJhwGuOfnNtQdj3JL
l0GnYxTZsFEuKgZsdN/VyS1fLlrhHK/m3aulinZjBC3p34I0+/cLmu3z4y4vfQ0+
duTHg1ECgYB98Z0eCi/ct+m+B3YhCEdcXUzvIZY0sEJUlqIiGyxkLuVEdIPIFUqj
f1+VVZQA0d6BwruDSptq8x5aR3rdAlb5A71NYWQGOIPa2E5SIFZmzrZjyeeCfyB8
eMOrE2W6flCRaTDOH4kFuw4JqrymBLcgP/OTYO0T9MCOKeqP0wbyNg==
-----END RSA PRIVATE KEY-----`
const iosEncodedMessage = `xW7YdqRZPxMjUydRuY/bWO78Jvz/GM9qx+0soQEsheqfs+5nLugkBXiJC9J6if3j
oCH/uBLYC41X6tlpX/L/u+ujaYQTIRcnL1f74ZFcX8Ox1vTp47Ie5XteRcLbuAmk
vOzQ41q/ddUe8co67ShuiTmwI3Q4bUNukHEkwcpbD20JllKRR3wfYCoej05O29Xj
9QuO0gKjEis5le6dWrMuVQVT70rBZQkAoBAesSjEYw0LKKjyylpUHmNy7y1XNbb2
LA8kC70ZvNWYL+cIU2ZKts9HYtTbIAonL91uP6Bf+M0uUkqc2zxEL9EpFmwGx3Q0
JQUqPQPB+wHb7DlDFJdQ6A==`
const message = await RSA.decrypt(iosEncodedMessage, iosPkcs1PrivateKey)
console.log('ios decoded message:', message);
}
const signDemo = async () => {
console.log('signDemo')
const keys = await RSA.generate()
const signature = await RSA.sign(secret, keys.private)
console.log('signature', signature);
const valid = await RSA.verify(signature, secret, keys.public)
console.log('verified', valid);
}