Categorygithub.com/rkcloudchain/cccsp
modulepackage
1.1.2
Repository: https://github.com/rkcloudchain/cccsp.git
Documentation: pkg.go.dev

# README

CCCSP

Build Status codecov Go Report Card

cccsp is the CloudChain Cryptographic Service Provider that offers the implementation of cryptographic standards and algorithms.

cccsp provides the following services:

  • Encrypt - Encryption operation
  • Decrypt - Decryption operation
  • Sign - Signature operation
  • Verify - Verification operation
  • Hash - Hash calculation

cccsp supports a variety of encryption and signature algorithms, including AES, RSA, and ECDSA. Support multiple hash clusters, including sha1, sha256, sha384, sha512, sha3_256, sha3_384, sha3_512.

Install

With a correctly configured Go toolchain:

go get -u github.com/rkcloudchain/cccsp

Example

First of all, you need to instantiate a KeyStore object. Currently we provide two types of KeyStore: memory-based and file system based.

ks, _ := provider.NewFileKeyStore("/path/to/store") // or ks := NewMemoryKeyStore()

Next, let's creating a cccsp instance.

csp, _ := provider.New(ks)

Now you can generate a new key

key, _ := csp.KeyGenerate("ECDSA256", false)

You can sign with the generated key

ptext := []byte("bla bla bla")
sigma, err := csp.Sign(key, ptext, nil)

Or verify that the signature is correct

valid, err := csp.Verify(key, sigma, ptext, nil)

The cccsp interface defines the following methods:

// CCCSP is the cloudchain cryptographic service provider that offers
// the implementation of cryptographic standards and algorithms
type CCCSP interface {
    // KeyGenerate generates a key.
    KeyGenerate(algorithm string, ephemeral bool) (Key, error)

    // KeyImport imports a key from its raw representation.
    KeyImport(raw interface{}, algorithm string, ephemeral bool) (Key, error)

    // GetKey returns the key this CSP associates to
    GetKey(id []byte) (Key, error)

    // Hash hashes messages using specified hash family.
    Hash(msg []byte, family string) ([]byte, error)

    // GetHash returns and instance of hash.Hash with hash algorithm
    GetHash(algo string) (hash.Hash, error)

    // Sign signs digest using key k.
    Sign(k Key, digest []byte, opts crypto.SignerOpts) ([]byte, error)

    // Verify verifies signature against key k and digest.
    Verify(k Key, signature, digest []byte, opts crypto.SignerOpts) (bool, error)

    // Encrypt encrypts plaintext using key k.
    Encrypt(k Key, plaintext []byte, opts EncrypterOpts) ([]byte, error)

    // Decrypt decrypts ciphertext using key k.
    Decrypt(k Key, ciphertext []byte, opts DecrypterOpts) ([]byte, error)
}

In addition to signing and verification, you can also perform encryption, decryption, and hash calculations.

License

cccsp is under the Apache 2.0 license. See the LICENSE file for details.

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

CCCSP is the cloudchain cryptographic service provider that offers the implementation of cryptographic standards and algorithms.
DecrypterOpts contains options for decrypting with a CSP.
Decryptor is a CCCSP-like interface that provides decryption algorithms.
EncrypterOpts contains options for encrypting with a CSP.
Encryptor is a CCCSP-like interface that provides encryption algorithms.
Hasher is a CCCSP-like interface that provides hash algorithms.
Key represents a cryptographic key.
KeyGenerator is a CCCSP-like interface that provides key generation algorithms.
KeyImporter is a CCCSP-like interface that provides key import algorithm.
KeyStore represents a storage system for cryptographic keys.
Signer is a CCCSP-like interface that provides signing algorithms.
Verifier is a CCCSP-like interface that provides verifying algorithms.