cccsp

package module
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2019 License: Apache-2.0 Imports: 2 Imported by: 6

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CCCSP

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)
}

CCCSP is the cloudchain cryptographic service provider that offers the implementation of cryptographic standards and algorithms

type DecrypterOpts

type DecrypterOpts interface{}

DecrypterOpts contains options for decrypting with a CSP.

type Decryptor

type Decryptor interface {
	Decrypt(k Key, ciphertext []byte, opts DecrypterOpts) ([]byte, error)
}

Decryptor is a CCCSP-like interface that provides decryption algorithms

type EncrypterOpts

type EncrypterOpts interface{}

EncrypterOpts contains options for encrypting with a CSP.

type Encryptor

type Encryptor interface {
	Encrypt(k Key, plaintext []byte, opts EncrypterOpts) ([]byte, error)
}

Encryptor is a CCCSP-like interface that provides encryption algorithms

type Hasher

type Hasher interface {
	Hash(msg []byte) ([]byte, error)
	GetHash() hash.Hash
}

Hasher is a CCCSP-like interface that provides hash algorithms

type Key

type Key interface {
	// Raw converts this key to its byte representation.
	Raw() ([]byte, error)

	// Identifier returns the identifier of this key
	Identifier() []byte

	// SKI is for compatibility with Hyperledger Fabric bccsp
	SKI() []byte

	// Private returns true if this key is a private key.
	// false otherwise
	Private() bool

	// Public returns the corresponding public key part of
	// an asymmetric public/private key pair.
	Public() (Key, error)
}

Key represents a cryptographic key

type KeyGenerator

type KeyGenerator interface {
	KeyGenerate() (Key, error)
}

KeyGenerator is a CCCSP-like interface that provides key generation algorithms.

type KeyImporter

type KeyImporter interface {
	KeyImport(raw interface{}) (Key, error)
}

KeyImporter is a CCCSP-like interface that provides key import algorithm

type KeyStore

type KeyStore interface {
	LoadKey([]byte) (Key, error)
	StoreKey(Key) error
}

KeyStore represents a storage system for cryptographic keys.

type Signer

type Signer interface {
	Sign(k Key, digest []byte, opts crypto.SignerOpts) ([]byte, error)
}

Signer is a CCCSP-like interface that provides signing algorithms

type Verifier

type Verifier interface {
	Verify(k Key, signature, digest []byte, opts crypto.SignerOpts) (bool, error)
}

Verifier is a CCCSP-like interface that provides verifying algorithms

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL