Documentation
¶
Overview ¶
Copyright 2023 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Variables
- func CryptoDecryptBasic(privKey []byte) func(string) IOE.IOEither[error, []byte]
- 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 CryptoSymmetricDecrypt(srcText string) func([]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 OpenSSLSymmetricDecrypt(token string) func([]byte) 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)
- type CertFingerprintFunc
- type Decryption
- 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 ( // OpenSSLDecryption returns the decryption environment using OpenSSL OpenSSLDecryption = IO.MakeIO(func() Decryption { return Decryption{ DecryptBasic: OpenSSLDecryptBasic, } }) // CryptoDecryption returns the decryption environment using golang crypto CryptoDecryption = IO.MakeIO(func() Decryption { return Decryption{ DecryptBasic: CryptoDecryptBasic, } }) // DefaultDecryption detects the decryption environment DefaultDecryption = F.Pipe1( validOpenSSL, IOE.Fold(F.Constant1[error](CryptoDecryption), F.Constant1[string](OpenSSLDecryption)), ) )
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) // CryptoAsymmetricDecrypt decrypts a piece of text using a private key CryptoAsymmetricDecrypt = cryptoAsymmetricDecrypt(privToRsaKey) )
var ( // OpenSSLSignDigest signs the sha256 digest using a private key OpenSSLSignDigest = handle(signDigest) // OpenSSLAsymmetricEncryptPubOrCert implements asymmetric encryption based on a public key or certificate based on the input OpenSSLAsymmetricEncryptPubOrCert = handle(asymmetricEncryptPubOrCert) // OpenSSLAsymmetricEncryptPub implements asymmetric encryption based on a public key OpenSSLAsymmetricEncryptPub = handle(asymmetricEncryptPub) // OpenSSLAsymmetricEncryptCert implements asymmetric encryption based on a certificate OpenSSLAsymmetricEncryptCert = handle(asymmetricEncryptCert) OpenSSLAsymmetricDecrypt = handle(asymmetricDecrypt) OpenSSLSymmetricEncrypt = 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 CryptoDecryptBasic ¶ added in v1.0.1
CryptoDecryptBasic implements basic decryption using golang crypto libraries given the private key
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 CryptoSymmetricDecrypt ¶ added in v1.0.1
CryptoSymmetricDecrypt encrypts a set of bytes using a password
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 OpenSSLSymmetricDecrypt ¶ added in v1.0.1
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 Decryption ¶ added in v1.0.1
type Decryption struct { // DecryptBasic implements basic decryption given the private key DecryptBasic func(privKey []byte) func(string) IOE.IOEither[error, []byte] }
Decryption captures the crypto functions required to implement the source providers
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)