https://github.com/cisco/node-jose这是我的代码示例:
let keystore1;
let keystore2;
keystore1 = JWK.createKeyStore();
keystore2 = JWK.createKeyStore();
const input = { message: { text: 'Привет!' } };
const priv1 = await keystore1.generate('EC', 'P-256', {
kid: '1gBdaS-G8RLax2qgObTD94w',
key_ops:["sign", "decrypt", "unwrap"]
});
const priv2 = await keystore2.generate('EC', 'P-256', {
kid: '2gBdaS-G8RLax2qgObTD94v',
key_ops:["sign", "decrypt", "unwrap"]
});
const pub1 = await JWK.asKey(priv1.toJSON());
const pub2 = await JWK.asKey(priv2.toJSON());
const encrypted = await JWE.createEncrypt(
{
format: 'compact',
fields: {
alg: 'ECDH-ES',
enc: 'A128CBC-HS256',
cty: 'json', // replace with JWT if you're encrypting a JWT...
},
},
{
key: pub2,
}
)
.update(JSON.stringify(input))
.final();
console.log('encrypted', encrypted);
const decrypted = await JWE.createDecrypt(priv2).decrypt(encrypted);
console.log('decrypted', JSON.parse(decrypted.payload.toString()));//模拟只能访问公钥,通常这是您的起点,因为只有在为他人加密消息时才能访问公共组件。
用拉丁语解密ok!如何用西里尔文解密,请帮帮我。
发布于 2021-11-14 22:08:34
https://stackoverflow.com/questions/69967314
复制相似问题