ocrypto

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: BSD-3-Clause-Clear Imports: 21 Imported by: 3

README

Internal Module

These modules are used by other http://github.com/opentdf/ projects, and are not intended for use elsewhere.

Documentation

Index

Constants

View Source
const DefaultNonceSize = 16

DefaultNonceSize The default nonce size for the TDF3 encryption.

View Source
const GcmStandardNonceSize = 12

Variables

This section is empty.

Functions

func Base64Decode

func Base64Decode(data []byte) ([]byte, error)

Base64Decode Decode the data using base64 decoding.

func Base64Encode

func Base64Encode(data []byte) []byte

Base64Encode Encode the data to base64 encoding. Note: bas64 encoding causing ~33% overhead.

func CalculateHKDF added in v0.1.1

func CalculateHKDF(salt []byte, secret []byte) ([]byte, error)

CalculateHKDF generate a key using key derivation function.

func CalculateSHA256

func CalculateSHA256(data []byte) []byte

CalculateSHA256 Calculate the SHA256 checksum of the data(32 bytes).

func CalculateSHA256Hmac

func CalculateSHA256Hmac(secret, data []byte) []byte

CalculateSHA256Hmac Calculate the hmac of the data with given secret.

func CompressedECPublicKey added in v0.1.4

func CompressedECPublicKey(mode ECCMode, pubKey ecdsa.PublicKey) ([]byte, error)

CompressedECPublicKey - return a compressed key from the supplied curve and public key

func ComputeECDHKey added in v0.1.1

func ComputeECDHKey(privateKeyInPem []byte, publicKeyInPem []byte) ([]byte, error)

ComputeECDHKey calculate shared secret from public key from one party and the private key from another party.

func ComputeECDHKeyFromEC added in v0.1.4

func ComputeECDHKeyFromEC(publicKey *ecdsa.PublicKey, privateKey *ecdsa.PrivateKey) ([]byte, error)

func ComputeECDHKeyFromECDHKeys added in v0.1.4

func ComputeECDHKeyFromECDHKeys(publicKey *ecdh.PublicKey, privateKey *ecdh.PrivateKey) ([]byte, error)

func ComputeECDSASig added in v0.1.4

func ComputeECDSASig(digest []byte, privKey *ecdsa.PrivateKey) ([]byte, []byte, error)

ComputeECDSASig compute ecdsa signature

func ConvertToECDHPrivateKey added in v0.1.1

func ConvertToECDHPrivateKey(key interface{}) (*ecdh.PrivateKey, error)

ConvertToECDHPrivateKey convert the ec private key to ECDH private key

func ConvertToECDHPublicKey added in v0.1.1

func ConvertToECDHPublicKey(key interface{}) (*ecdh.PublicKey, error)

ConvertToECDHPublicKey convert the ec public key to ECDH public key

func ECPrivateKeyFromPem added in v0.1.1

func ECPrivateKeyFromPem(privateECKeyInPem []byte) (*ecdh.PrivateKey, error)

ECPrivateKeyFromPem generate ec private from pem format

func ECPrivateKeyInPemFormat added in v0.1.4

func ECPrivateKeyInPemFormat(privateKey ecdsa.PrivateKey) (string, error)

ECPrivateKeyInPemFormat Returns private key in pem format.

func ECPubKeyFromPem added in v0.1.1

func ECPubKeyFromPem(pemECPubKey []byte) (*ecdh.PublicKey, error)

ECPubKeyFromPem generate ec public from pem format

func ECPublicKeyInPemFormat added in v0.1.4

func ECPublicKeyInPemFormat(publicKey ecdsa.PublicKey) (string, error)

ECPublicKeyInPemFormat Returns public key in pem format.

func GetECCurveFromECCMode added in v0.1.5

func GetECCurveFromECCMode(mode ECCMode) (elliptic.Curve, error)

GetECCurveFromECCMode return elliptic curve from ecc mode

func RandomBytes

func RandomBytes(size int) ([]byte, error)

RandomBytes Generates random bytes of given size.

func SHA256AsHex

func SHA256AsHex(data []byte) []byte

SHA256AsHex Calculate the SHA256 checksum of the data and return in hex format(64 bytes).

func SHA256HmacAsHex

func SHA256HmacAsHex(secret, data []byte) []byte

SHA256HmacAsHex Calculate the hmac of the data with given secret and return in hex format.

func UncompressECPubKey added in v0.1.5

func UncompressECPubKey(curve elliptic.Curve, compressedPubKey []byte) (*ecdsa.PublicKey, error)

UncompressECPubKey create EC public key from compressed form

func VerifyECDSASig added in v0.1.5

func VerifyECDSASig(digest, r, s []byte, pubKey *ecdsa.PublicKey) bool

VerifyECDSASig verify ecdsa signature.

Types

type AesGcm

type AesGcm struct {
	// contains filtered or unexported fields
}

func NewAESGcm

func NewAESGcm(key []byte) (AesGcm, error)

NewAESGcm creates and returns a new AesGcm.

func (AesGcm) Decrypt

func (aesGcm AesGcm) Decrypt(data []byte) ([]byte, error)

Decrypt decrypts data with symmetric key. NOTE: This method use nonce of 12 bytes and auth tag as aes block size(16 bytes) also expects IV as preamble of data.

func (AesGcm) DecryptWithIVAndTagSize added in v0.1.4

func (aesGcm AesGcm) DecryptWithIVAndTagSize(iv, data []byte, authTagSize int) ([]byte, error)

DecryptWithIVAndTagSize decrypts data with symmetric key. NOTE: This method expects gcm standard nonce size(12) of iv.

func (AesGcm) DecryptWithTagSize

func (aesGcm AesGcm) DecryptWithTagSize(data []byte, authTagSize int) ([]byte, error)

DecryptWithTagSize decrypts data with symmetric key. NOTE: This method expects gcm standard nonce size(12) of iv.

func (AesGcm) Encrypt

func (aesGcm AesGcm) Encrypt(data []byte) ([]byte, error)

Encrypt encrypts data with symmetric key. NOTE: This method use nonce of 12 bytes and auth tag as aes block size(16 bytes).

func (AesGcm) EncryptWithIV

func (aesGcm AesGcm) EncryptWithIV(iv, data []byte) ([]byte, error)

EncryptWithIV encrypts data with symmetric key. NOTE: This method use default auth tag as aes block size(16 bytes) and expects iv of 16 bytes.

func (AesGcm) EncryptWithIVAndTagSize

func (aesGcm AesGcm) EncryptWithIVAndTagSize(iv, data []byte, authTagSize int) ([]byte, error)

EncryptWithIVAndTagSize encrypts data with symmetric key. NOTE: This method expects gcm standard nonce size(12) of iv.

type AsymDecryption

type AsymDecryption struct {
	PrivateKey *rsa.PrivateKey
}

func NewAsymDecryption

func NewAsymDecryption(privateKeyInPem string) (AsymDecryption, error)

NewAsymDecryption creates and returns a new AsymDecryption.

func (AsymDecryption) Decrypt

func (asymDecryption AsymDecryption) Decrypt(data []byte) ([]byte, error)

Decrypt decrypts ciphertext with private key.

type AsymEncryption

type AsymEncryption struct {
	PublicKey *rsa.PublicKey
}

func NewAsymEncryption

func NewAsymEncryption(publicKeyInPem string) (AsymEncryption, error)

NewAsymEncryption creates and returns a new AsymEncryption.

func (AsymEncryption) Encrypt

func (asymEncryption AsymEncryption) Encrypt(data []byte) ([]byte, error)

Encrypt encrypts data with public key.

func (AsymEncryption) PublicKeyInPemFormat

func (asymEncryption AsymEncryption) PublicKeyInPemFormat() (string, error)

PublicKeyInPemFormat Returns public key in pem format.

type ECCMode

type ECCMode uint8
const (
	ECCModeSecp256r1 ECCMode = 0
	ECCModeSecp384r1 ECCMode = 1
	ECCModeSecp521r1 ECCMode = 2
	ECCModeSecp256k1 ECCMode = 3
)

type ECKeyPair

type ECKeyPair struct {
	PrivateKey *ecdsa.PrivateKey
}

func NewECKeyPair

func NewECKeyPair(mode ECCMode) (ECKeyPair, error)

NewECKeyPair Generates an EC key pair of the given bit size.

func (ECKeyPair) KeySize

func (keyPair ECKeyPair) KeySize() (int, error)

KeySize Return the size of this ec key pair.

func (ECKeyPair) PrivateKeyInPemFormat

func (keyPair ECKeyPair) PrivateKeyInPemFormat() (string, error)

PrivateKeyInPemFormat Returns private key in pem format.

func (ECKeyPair) PublicKeyInPemFormat

func (keyPair ECKeyPair) PublicKeyInPemFormat() (string, error)

PublicKeyInPemFormat Returns public key in pem format.

type RsaKeyPair

type RsaKeyPair struct {
	// contains filtered or unexported fields
}

func FromRSA added in v0.1.4

func FromRSA(k *rsa.PrivateKey) RsaKeyPair

func NewRSAKeyPair

func NewRSAKeyPair(bits int) (RsaKeyPair, error)

NewRSAKeyPair Generates an RSA key pair of the given bit size.

func (RsaKeyPair) KeySize

func (keyPair RsaKeyPair) KeySize() (int, error)

KeySize Return the size of this rsa key pair.

func (RsaKeyPair) PrivateKeyInPemFormat

func (keyPair RsaKeyPair) PrivateKeyInPemFormat() (string, error)

PrivateKeyInPemFormat Returns private key in pem format.

func (RsaKeyPair) PublicKeyInPemFormat

func (keyPair RsaKeyPair) PublicKeyInPemFormat() (string, error)

PublicKeyInPemFormat Returns public key in pem format.

Jump to

Keyboard shortcuts

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