@sec-block/secjs-crypto
generate private key ande public key for encryption, decryption and sign, verify
Last updated 2 years ago by g277321 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @sec-block/secjs-crypto 
SYNC missed versions from official npm registry.

JavaScript Style Guide

[JavaScript Style Guide]

secCrypto

using EC crypto generate privat key and public key it also can be used for user authentication class secCrypto could encrypt and decrypt message

Kind: global class

Example

const secCrypto = require('../secCrypto_lib')


let TestSecCrypto = new SecCrypto()

secCrypto.generateCryptoPrivKey()

Kind: instance method of secCrypto
Example

let privateKey = TestSecCrypto.getCryptoPrivKey()

secCrypto.generateCryptoPubKey()

Corresponding uncompressed (65-byte) public key.

Kind: instance method of secCrypto

let publicKey = TestSecCrypt.getCryptoPubKey()

secCrypto.secSign(privateKey, str, callback)

Kind: instance method of secCrypto

Param Type Description
privateKey Buffer using private key signature message
str string input private key and message by string
callback Buffer message will be translated and saved in buffer

secCrypto.secVerify(publicKey, sig)

sig is from secSign() cipher verify user privat key and identity

Kind: instance method of secCrypto

Param Type Description
publicKey Buffer input public key and using public key decryption signature
sig Buffer decrypt signature and verify identify

Example

TestSecCrypto.secSign(privateKey,str,(sig)=>{
    console.log('Signature in DER format:', sig)

    TestSecCrypto.secVerify(publicKey,sig)

})

secCrypto.secEncrypt(publicKey, cryptoMsg, callback)

user decrypting the message with privat key.

Kind: instance method of secCrypto

Param Type Description
publicKey Buffer input public key and use public key encrypt message
cryptoMsg string input message
callback Buffer callback cipher

secCrypto.secDecrypt(privateKey, encrypted, callback)

using private key decrypt cipher

Kind: instance method of secCrypto

Param Type Description
privateKey Buffer input private key and use private key decrypt cipher
encrypted Buffer input cipher
callback string callback plaintext

Example

let text = 'Hello World'
TestSecCrypto.secEncrypt(publicKey,text,(cipher)=>{

    console.log('cipher:',cipher)

    TestSecCrypto.secDecrypt(privateKey,cipher,(plaintext)=>{
        console.log('Plaintext:', plaintext)

        let strPlaintext = plaintext.toString()
        console.log('Plaintext to String:', strPlaintext)
    })
    
})

secCrypto.getCryptoPrivKey()

return private key

Kind: instance method of secCrypto

secCrypto.getCryptoPubKey()

return public key

Kind: instance method of secCrypto

Current Tags

  • 1.0.7                                ...           latest (2 years ago)

5 Versions

  • 1.0.7                                ...           2 years ago
  • 1.0.6                                ...           2 years ago
  • 1.0.5                                ...           2 years ago
  • 1.0.4                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 0
Dependencies (8)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |