@sec-block/secjs-crypto

generate private key ande public key for encryption, decryption and sign, verify

Usage no npm install needed!

<script type="module">
  import secBlockSecjsCrypto from 'https://cdn.skypack.dev/@sec-block/secjs-crypto';
</script>

README

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
```js
TestSecCrypto.secSign(privateKey,str,(sig)=>{
console.log('Signature in DER format:', sig)
TestSecCrypto.secVerify(publicKey,sig)

})

<a name="secCrypto+secEncrypt"></a>

### secCrypto.secEncrypt(publicKey, cryptoMsg, callback)
user decrypting the message with privat key.

**Kind**: instance method of [<code>secCrypto</code>](#secCrypto)  

| Param | Type | Description |
| --- | --- | --- |
| publicKey | <code>Buffer</code> | input public key and use public key encrypt message |
| cryptoMsg | <code>string</code> | input message |
| callback | <code>Buffer</code> | callback cipher |

<a name="secCrypto+secDecrypt"></a>

### secCrypto.secDecrypt(privateKey, encrypted, callback)
using private key decrypt cipher

**Kind**: instance method of [<code>secCrypto</code>](#secCrypto)  

| Param | Type | Description |
| --- | --- | --- |
| privateKey | <code>Buffer</code> | input private key and use private key decrypt cipher |
| encrypted | <code>Buffer</code> | input cipher |
| callback | <code>string</code> | callback plaintext |
**Example**
```js
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