Const
公钥
需要解密的内容,可以是原始数据,也可以是 hex 或 base64 编码后的数据
输出格式,默认为 ArrayBuffer,可选 base64 和 hex,返回编码后的字符串
解密选项
解密的结果
解密。
import x509 from 'pts/crypto/x509';
import crypto from 'pts/crypto';
import util from 'pts/util';
const publicKeyPem = open("./ca.pem");
const privateKeyPem = open("./ca.key.pem");
let publicKey = x509.parseCertificateToPublicKey(publicKeyPem);
let privateKey = x509.parsePrivateKey(privateKeyPem);
export default function() {
let data = "hello world";
let outputEncoding = "base64";
let options = {
type: "oaep",
hash: "sha256",
};
let dataEncoded = util.base64Encoding(data);
let encrypted = crypto.encrypt(publicKey, dataEncoded, outputEncoding, options);
let decrypted = crypto.decryptToString(privateKey, encrypted, options);
// hello world
console.log(decrypted);
}
公钥
需要解密的内容,可以是原始数据,也可以是 hex 或 base64 编码后的数据
输出格式,默认为 ArrayBuffer,可选 base64 和 hex,返回编码后的字符串
解密选项
解密的结果
加密。
import x509 from 'pts/crypto/x509';
import crypto from 'pts/crypto';
import util from 'pts/util';
const publicKeyPem = open("./ca.pem");
const privateKeyPem = open("./ca.key.pem");
let publicKey = x509.parseCertificateToPublicKey(publicKeyPem);
let privateKey = x509.parsePrivateKey(privateKeyPem);
export default function() {
let data = "hello world";
let outputEncoding = "base64";
let options = {
type: "oaep",
hash: "sha256",
};
let dataEncoded = util.base64Encoding(data);
let encrypted = crypto.encrypt(publicKey, dataEncoded, outputEncoding, options);
let decrypted = crypto.decryptToString(privateKey, encrypted, options);
// hello world
console.log(decrypted);
}
公钥
需要加密的内容,可以是原始数据,也可以是 hex 或 base64 编码后的数据
输出格式,默认为 ArrayBuffer,可选 base64 和 hex,返回编码后的字符串
加密选项
加密后的内容
加密。
import x509 from 'pts/crypto/x509';
import crypto from 'pts/crypto';
const publicKeyPem = open("./ca.pem");
const privateKeyPem = open("./ca.key.pem");
let publicKey = x509.parseCertificateToPublicKey(publicKeyPem);
let privateKey = x509.parsePrivateKey(privateKeyPem);
export default function() {
let data = "hello world";
let outputEncoding = "base64";
let options = {
type: "oaep",
hash: "sha256",
};
let encrypted = crypto.encryptFromString(publicKey, data, outputEncoding, options);
let decrypted = crypto.decryptToString(privateKey, encrypted, options);
// hello world
console.log(decrypted);
}
公钥
需要加密的内容
输出格式,默认为 ArrayBuffer,可选 base64 和 hex,返回编码后的字符串
加密选项
加密后的内容
签名。
import x509 from 'pts/crypto/x509';
import crypto from 'pts/crypto';
import util from 'pts/util';
const publicKeyPem = open("./ca.pem");
const privateKeyPem = open("./ca.key.pem");
let publicKey = x509.parseCertificateToPublicKey(publicKeyPem);
let privateKey = x509.parsePrivateKey(privateKeyPem);
export default function () {
let message = "This is a message.";
let messageEncoded = util.base64Encoding(message);
let options = {};
let signed = crypto.sign(privateKey, "sha256", messageEncoded, "base64", options);
let verified = crypto.verify(publicKey, "sha256", messageEncoded, signed, options);
// true
console.log(verified);
}
私钥
哈希算法,默认为 sha256,支持算法的包括 md5 sha1 sha256 sha512 sha3_256 sha3_512 等
需要签名的内容,可以是原始数据 ArrayBuffer,也可以是 hex 或 base64 编码后的字符串
输出格式,默认为 ArrayBuffer,可选 base64 和 hex,返回编码后的字符串
签名选项
签名结果
签名。
import x509 from 'pts/crypto/x509';
import crypto from 'pts/crypto';
import util from 'pts/util';
const publicKeyPem = open("./ca.pem");
const privateKeyPem = open("./ca.key.pem");
let publicKey = x509.parseCertificateToPublicKey(publicKeyPem);
let privateKey = x509.parsePrivateKey(privateKeyPem);
export default function () {
let message = "This is a message.";
let messageEncoded = util.base64Encoding(message);
let options = {};
let signed = crypto.signString(privateKey, "sha256", message, "base64", options);
let verified = crypto.verify(publicKey, "sha256", messageEncoded, signed, options);
// true
console.log(verified);
}
私钥
哈希算法,默认为 sha256,支持算法的包括 md5 sha1 sha256 sha512 sha3_256 sha3_512 等
需要签名的内容,原始数据字符串
输出格式,默认为 ArrayBuffer,可选 base64 和 hex,返回编码后的字符串
签名选项
签名结果
验签。
import x509 from 'pts/crypto/x509';
import crypto from 'pts/crypto';
import util from 'pts/util';
const publicKeyPem = open("./ca.pem");
const privateKeyPem = open("./ca.key.pem");
let publicKey = x509.parseCertificateToPublicKey(publicKeyPem);
let privateKey = x509.parsePrivateKey(privateKeyPem);
export default function () {
let message = "This is a message.";
let messageEncoded = util.base64Encoding(message);
let options = {};
let signed = crypto.sign(privateKey, "sha256", messageEncoded, "base64", options);
let verified = crypto.verify(publicKey, "sha256", messageEncoded, signed, options);
// true
console.log(verified);
}
公钥
哈希算法,默认为 sha256,支持算法的包括 md5 sha1 sha256 sha512 sha3_256 sha3_512 等
被签名的内容,可以是原始数据 ArrayBuffer,也可以是 hex 或 base64 编码后的字符串
需要验证的签名结果,可以是 ArrayBuffer,也可以是 hex 或 base64 编码后的字符串
验签选项
验签结果
验签。
import x509 from 'pts/crypto/x509';
import crypto from 'pts/crypto';
import util from 'pts/util';
const publicKeyPem = open("./ca.pem");
const privateKeyPem = open("./ca.key.pem");
let publicKey = x509.parseCertificateToPublicKey(publicKeyPem);
let privateKey = x509.parsePrivateKey(privateKeyPem);
export default function () {
let message = "This is a message.";
let messageEncoded = util.base64Encoding(message);
let options = {};
let signed = crypto.sign(privateKey, "sha256", messageEncoded, "base64", options);
let verified = crypto.verifyString(publicKey, "sha256", message, signed, options);
// true
console.log(verified);
}
公钥
哈希算法,默认为 sha256,支持算法的包括 md5 sha1 sha256 sha512 sha3_256 sha3_512 等
被签名的内容,原始数据字符串
需要验证的签名结果,可以是 ArrayBuffer,也可以是 hex 或 base64 编码后的字符串
验签选项
验签结果
解密。