Documentation
¶
Index ¶
- Variables
- func CryptoEncryptBasic(pubKeyOrCert []byte) func([]byte) IOE.IOEither[error, string]
- func CryptoRandomPassword(count int) IOE.IOEither[error, []byte]
- func CryptoSignDigest(privKey []byte) func(data []byte) IOE.IOEither[error, []byte]
- func CryptoSymmetricEncrypt(srcPlainbBytes []byte) func([]byte) IOE.IOEither[error, string]
- func DecryptBasic(asymmDecrypt func(string) IOE.IOEither[error, []byte], ...) func(string) IOE.IOEither[error, []byte]
- func EncryptBasic(genPwd IOE.IOEither[error, []byte], ...) func([]byte) IOE.IOEither[error, string]
- func OpenSSLCertFingerprint(cert []byte) E.Either[error, []byte]
- func OpenSSLDecryptBasic(privKey []byte) func(string) IOE.IOEither[error, []byte]
- func OpenSSLEncryptBasic(pubOrCert []byte) func([]byte) IOE.IOEither[error, string]
- func OpenSSLPrivKeyFingerprint(privKey []byte) E.Either[error, []byte]
- func OpenSSLPublicKey(privKey []byte) E.Either[error, []byte]
- func OpenSSLPublicKeyFromCertificate(certificate []byte) E.Either[error, []byte]
- func OpenSSLRandomPassword(count int) IOE.IOEither[error, []byte]
- func OpenSSLVerifyDigest(pubKey []byte) func(data []byte) func(signature []byte) IOO.IOOption[error]
- func SignatureTest(privateKey IOE.IOEither[error, []byte], ...) func(t *testing.T)
- func SymmetricDecrypt(token string) func([]byte) IOE.IOEither[error, []byte]
- type CertFingerprintFunc
- type EncryptBasicFunc
- type Encryption
- func (enc Encryption) GetCertFingerprint() CertFingerprintFunc
- func (enc Encryption) GetEncryptBasic() EncryptBasicFunc
- func (enc Encryption) GetPrivKey() Key
- func (enc Encryption) GetPrivKeyFingerprint() PrivKeyFingerprintFunc
- func (enc Encryption) GetPubKey() PubKeyFunc
- func (enc Encryption) GetSignDigest() SignDigestFunc
- type Executor
- type Key
- type PrivKeyFingerprintFunc
- type PubKeyFunc
- type SignDigestFunc
Constants ¶
This section is empty.
Variables ¶
var ( // OpenSSLEncryption returns the encryption environment using OpenSSL OpenSSLEncryption = IO.MakeIO(func() Encryption { return Encryption{ EncryptBasic: OpenSSLEncryptBasic, CertFingerprint: OpenSSLCertFingerprint, PrivKeyFingerprint: OpenSSLPrivKeyFingerprint, PrivKey: OpenSSLPrivateKey, PubKey: OpenSSLPublicKey, SignDigest: OpenSSLSignDigest, } }) // CryptoEncryption returns the encryption environment using golang crypto CryptoEncryption = IO.MakeIO(func() Encryption { return Encryption{ EncryptBasic: CryptoEncryptBasic, CertFingerprint: CryptoCertFingerprint, PrivKeyFingerprint: CryptoPrivKeyFingerprint, PrivKey: CryptoPrivateKey, PubKey: CryptoPublicKey, SignDigest: CryptoSignDigest, } }) // DefaultEncryption detects the encryption environment DefaultEncryption = F.Pipe1( validOpenSSL, IOE.Fold(F.Constant1[error](CryptoEncryption), F.Constant1[string](OpenSSLEncryption)), ) )
var ( // CryptoCertFingerprint computes the fingerprint of a certificate using the crypto library CryptoCertFingerprint = F.Flow5( pemDecodeFirstCertificate, E.Chain(parseCertificateE), E.Map[error](rawFromCertificate), E.Map[error](sha256.Sum256), E.Map[error](shaToBytes), ) // CryptoPrivKeyFingerprint computes the fingerprint of a private key using the crypto library CryptoPrivKeyFingerprint = F.Flow7( pemDecodeE, E.Chain(parsePrivateKeyE), E.Map[error](privToPub), E.Map[error](pubToAny), E.Chain(marshalPKIXPublicKeyE), E.Map[error](sha256.Sum256), E.Map[error](shaToBytes), ) // CryptoVerifyDigest verifies the signature of the input data against a signature CryptoVerifyDigest = F.Flow2( pubToRsaKey, E.Fold(errorValidator, verifyPKCS1v15), ) // CryptoPublicKey extracts the public key from a private key CryptoPublicKey = F.Flow6( pemDecodeE, E.Chain(parsePrivateKeyE), E.Map[error](privToPub), E.Map[error](pubToAny), E.Chain(marshalPKIXPublicKeyE), E.Map[error](func(data []byte) []byte { return pem.EncodeToMemory( &pem.Block{ Type: EC.TypePublicKey, Bytes: data, }, ) }), ) // IsPublicKey checks if a PEM block is a public key IsPublicKey = EC.IsType(EC.TypePublicKey) // IsCertificate checks if a PEM block is a certificate IsCertificate = EC.IsType(EC.TypeCertificate) // CryptoAsymmetricEncryptPubOrCert encrypts a piece of text using a public key or a certificate CryptoAsymmetricEncryptPubOrCert = cryptoAsymmetricEncrypt(pubOrCertToRsaKey) // CryptoAsymmetricEncryptPub encrypts a piece of text using a public key CryptoAsymmetricEncryptPub = cryptoAsymmetricEncrypt(pubToRsaKey) // CryptoAsymmetricEncryptCert encrypts a piece of text using a certificate CryptoAsymmetricEncryptCert = cryptoAsymmetricEncrypt(certToRsaKey) )
var ( // OpenSSLSignDigest signs the sha256 digest using a private key OpenSSLSignDigest = handle(signDigest) // AsymmetricEncryptPubOrCert implements asymmetric encryption based on a public key or certificate based on the input AsymmetricEncryptPubOrCert = handle(asymmetricEncryptPubOrCert) // AsymmetricEncryptPub implements asymmetric encryption based on a public key AsymmetricEncryptPub = handle(asymmetricEncryptPub) // AsymmetricEncryptCert implements asymmetric encryption based on a certificate AsymmetricEncryptCert = handle(asymmetricEncryptCert) AsymmerticDecrypt = handle(asymmetricDecrypt) SymmetricEncrypt = handle(symmetricEncrypt) // CertSerial gets the serial number from a certificate CertSerial = F.Flow2( OpenSSL("x509", "-serial", "-noout"), mapStdout, ) // OpenSSLPrivateKey generates a private key OpenSSLPrivateKey = F.Pipe2( emptyBytes, OpenSSL("genrsa", "4096"), mapStdout, ) )
var CryptoPrivateKey = F.Pipe1( IOE.TryCatchError(func() (*rsa.PrivateKey, error) { return rsa.GenerateKey(rand.Reader, 4096) }), IOE.Map[error](privKeyToPem), )
CryptoPrivateKey generates a private key
Functions ¶
func CryptoEncryptBasic ¶
CryptoEncryptBasic implements basic encryption using golang crypto libraries given the public key or certificate
func CryptoRandomPassword ¶
CryptoRandomPassword creates a random password of given length using characters from the base64 alphabet only
func CryptoSignDigest ¶
CryptoSignDigest generates a signature across the sha256 of the message privkey - the private key used to compute the signature data - the message to be signed
func CryptoSymmetricEncrypt ¶
CryptoSymmetricEncrypt encrypts a set of bytes using a password
func DecryptBasic ¶
func DecryptBasic( asymmDecrypt func(string) IOE.IOEither[error, []byte], symmDecrypt func(string) func([]byte) IOE.IOEither[error, []byte], ) func(string) IOE.IOEither[error, []byte]
DecryptBasic implements the basic decryption operations
func EncryptBasic ¶
func EncryptBasic( genPwd IOE.IOEither[error, []byte], asymmEncrypt func([]byte) IOE.IOEither[error, string], symmEncrypt EncryptBasicFunc, ) func([]byte) IOE.IOEither[error, string]
EncryptBasic implements the basic encryption operations
func OpenSSLDecryptBasic ¶
OpenSSLDecryptBasic implements basic decryption using openSSL given the private key
func OpenSSLEncryptBasic ¶
OpenSSLEncryptBasic implements basic encryption using openSSL given the certificate or public key
func OpenSSLRandomPassword ¶
OpenSSLRandomPassword creates a random password of given length using characters from the base64 alphabet only
func OpenSSLVerifyDigest ¶
func OpenSSLVerifyDigest(pubKey []byte) func(data []byte) func(signature []byte) IOO.IOOption[error]
OpenSSLVerifyDigest verifies the signature of the input data against a signature
func SignatureTest ¶
Types ¶
type EncryptBasicFunc ¶
type Encryption ¶
type Encryption struct { // EncryptBasic implements basic encryption given the certificate (side effect because of random passphrase) EncryptBasic EncryptBasicFunc // CertFingerprint computes the fingerprint of a certificate CertFingerprint CertFingerprintFunc // PrivKeyFingerprint computes the fingerprint of a private key PrivKeyFingerprint PrivKeyFingerprintFunc // PrivKey computes a new private key PrivKey Key // PubKey computes a public key from a private key PubKey PubKeyFunc // SignDigest computes the sha256 signature using a private key (side effect because of RSA blinding) SignDigest SignDigestFunc }
Encryption captures the crypto functions required to implement the source providers
func (Encryption) GetCertFingerprint ¶
func (enc Encryption) GetCertFingerprint() CertFingerprintFunc
CertFingerprint computes the fingerprint of a certificate
func (Encryption) GetEncryptBasic ¶
func (enc Encryption) GetEncryptBasic() EncryptBasicFunc
EncryptBasic implements basic encryption given the certificate (side effect because of random passphrase)
func (Encryption) GetPrivKey ¶
func (enc Encryption) GetPrivKey() Key
PrivKey computes a new private key
func (Encryption) GetPrivKeyFingerprint ¶
func (enc Encryption) GetPrivKeyFingerprint() PrivKeyFingerprintFunc
PrivKeyFingerprint computes the fingerprint of a private key
func (Encryption) GetPubKey ¶
func (enc Encryption) GetPubKey() PubKeyFunc
PubKey computes a public key from a private key
func (Encryption) GetSignDigest ¶
func (enc Encryption) GetSignDigest() SignDigestFunc
SignDigest computes the sha256 signature using a private key (side effect because of RSA blinding)