@sec-block/secjs-crypto

1.0.7 • Public • Published

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

Package Sidebar

Install

npm i @sec-block/secjs-crypto

Weekly Downloads

0

Version

1.0.7

License

MIT

Unpacked Size

29.2 kB

Total Files

13

Last publish

Collaborators

  • abysmli
  • bi7012xiao
  • feiminhao
  • g277321
  • tornadoming
  • xinnnnn
  • zuweihan1992