本文整理匯總了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');
}