plugins/tests/crypto_tests/sm2_test.js
Star b6bb3098bc update dao
many other updates
2024-03-24 12:28:02 +08:00

11 lines
379 B
JavaScript

import crypto from "apigo.cloud/git/apigo/plugins/crypto"
let [priKey, pubKey] = crypto.sm2.genKey()
let s1 = crypto.sm2.sign('hello 123', priKey)
if(!crypto.sm2.verify('hello 123', s1, pubKey)) throw new Error('')
let s2 = crypto.sm2.encrypt('hello 123', pubKey)
let s3 = crypto.sm2.decrypt(s2, priKey)
if( s3 !== 'hello 123') throw new Error('sm2 decrypt error')
return true