ocrypto

package module
v0.0.0-...-1ac4089 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: BSD-3-Clause-Clear Imports: 17 Imported by: 2

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 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 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.

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