1.0.7 • Published 5 years ago

@sec-block/secjs-crypto v1.0.7

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

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

ParamTypeDescription
privateKeyBufferusing private key signature message
strstringinput private key and message by string
callbackBuffermessage 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

ParamTypeDescription
publicKeyBufferinput public key and using public key decryption signature
sigBufferdecrypt 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

ParamTypeDescription
publicKeyBufferinput public key and use public key encrypt message
cryptoMsgstringinput message
callbackBuffercallback cipher

secCrypto.secDecrypt(privateKey, encrypted, callback)

using private key decrypt cipher

Kind: instance method of secCrypto

ParamTypeDescription
privateKeyBufferinput private key and use private key decrypt cipher
encryptedBufferinput cipher
callbackstringcallback 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