本文整理汇总了TypeScript中crypto.createVerify函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createVerify函数的具体用法?TypeScript createVerify怎么用?TypeScript createVerify使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createVerify函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: QueryProcessManager
export const PM = new QueryProcessManager(module, async ({data, signature}) => {
const verifier = crypto.createVerify(Config.loginserverkeyalgo);
verifier.update(data);
let success = false;
try {
success = verifier.verify(Config.loginserverpublickey, signature, 'hex');
} catch (e) {}
return success;
});
示例2: if
client.on('authentication', ctx => {
if (ctx.method === 'password'
&& ctx.username === 'foo'
&& ctx.password === 'bar')
ctx.accept();
else if (ctx.method === 'publickey'
&& ctx.key.algo === pubKey.fulltype
&& buffersEqual(ctx.key.data, pubKey.public)) {
if (ctx.signature) {
var verifier = crypto.createVerify(ctx.sigAlgo);
verifier.update(ctx.blob);
if (verifier.verify(pubKey.publicOrig.toString("utf8"), ctx.signature))
ctx.accept();
else
ctx.reject();
} else {
// if no signature present, that means the client is just checking
// the validity of the given public key
ctx.accept();
}
} else
ctx.reject();
}).on('ready', () => {
示例3:
{
crypto.createSecretKey(Buffer.from('asdf'));
}
{
const { privateKey, publicKey } = crypto.generateKeyPairSync('ec', {
namedCurve: 'sect239k1'
});
const sign: crypto.Signer = crypto.createSign('SHA256');
sign.write('some data to sign');
sign.end();
const signature: string = sign.sign(privateKey, 'hex');
const verify: crypto.Verify = crypto.createVerify('SHA256');
verify.write('some data to sign');
verify.end();
verify.verify(publicKey, signature); // $ExpectType boolean
// ensure that instanceof works
verify instanceof crypto.Verify;
sign instanceof crypto.Signer;
}
{
const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
modulusLength: 2048,
});
const sign: crypto.Signer = crypto.createSign('SHA256');
示例4: function
export const verify = function(data, signature, key) {
let verifier = crypto.createVerify('RSA-SHA1')
verifier.update(data, 'utf8')
return verifier.verify(key, signature, 'base64')
}
示例5: verifySignature
export function verifySignature(message: string, signature: string, pandaPublicKey: string): boolean {
return crypto.createVerify('sha256WithRSAEncryption')
.update(message, 'utf8')
.verify(pandaPublicKey, signature, 'base64');
}