Documentation ¶
Index ¶
- Variables
- func Bcrypt(str cty.Value, cost ...cty.Value) (cty.Value, error)
- func Md5(str cty.Value) (cty.Value, error)
- func RsaDecrypt(ciphertext, privatekey cty.Value) (cty.Value, error)
- func Sha1(str cty.Value) (cty.Value, error)
- func Sha256(str cty.Value) (cty.Value, error)
- func Sha512(str cty.Value) (cty.Value, error)
Constants ¶
This section is empty.
Variables ¶
var BcryptFunc = function.New(&function.Spec{ Params: []function.Parameter{ { Name: "str", Type: cty.String, }, }, VarParam: &function.Parameter{ Name: "cost", Type: cty.Number, }, Type: function.StaticReturnType(cty.String), Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) { defaultCost := 10 if len(args) > 1 { var val int if err := gocty.FromCtyValue(args[1], &val); err != nil { return cty.UnknownVal(cty.String), err } defaultCost = val } if len(args) > 2 { return cty.UnknownVal(cty.String), fmt.Errorf("bcrypt() takes no more than two arguments") } input := args[0].AsString() out, err := bcrypt.GenerateFromPassword([]byte(input), defaultCost) if err != nil { return cty.UnknownVal(cty.String), fmt.Errorf("error occured generating password %s", err.Error()) } return cty.StringVal(string(out)), nil }, })
BcryptFunc is a function that computes a hash of the given string using the Blowfish cipher.
var Md5Func = makeStringHashFunction(md5.New, hex.EncodeToString)
Md5Func is a function that computes the MD5 hash of a given string and encodes it with hexadecimal digits.
var RsaDecryptFunc = function.New(&function.Spec{ Params: []function.Parameter{ { Name: "ciphertext", Type: cty.String, }, { Name: "privatekey", Type: cty.String, }, }, Type: function.StaticReturnType(cty.String), Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) { s := args[0].AsString() key := args[1].AsString() b, err := base64.StdEncoding.DecodeString(s) if err != nil { return cty.UnknownVal(cty.String), fmt.Errorf("failed to decode input %q: cipher text must be base64-encoded", s) } block, _ := pem.Decode([]byte(key)) if block == nil { return cty.UnknownVal(cty.String), fmt.Errorf("failed to parse key: no key found") } if block.Headers["Proc-Type"] == "4,ENCRYPTED" { return cty.UnknownVal(cty.String), fmt.Errorf( "failed to parse key: password protected keys are not supported. Please decrypt the key prior to use", ) } x509Key, err := x509.ParsePKCS1PrivateKey(block.Bytes) if err != nil { return cty.UnknownVal(cty.String), err } out, err := rsa.DecryptPKCS1v15(nil, x509Key, b) if err != nil { return cty.UnknownVal(cty.String), err } return cty.StringVal(string(out)), nil }, })
RsaDecryptFunc is a function that decrypts an RSA-encrypted ciphertext.
var Sha1Func = makeStringHashFunction(sha1.New, hex.EncodeToString)
Sha1Func is a function that computes the SHA1 hash of a given string and encodes it with hexadecimal digits.
var Sha256Func = makeStringHashFunction(sha256.New, hex.EncodeToString)
Sha256Func is a function that computes the SHA256 hash of a given string and encodes it with hexadecimal digits.
var Sha512Func = makeStringHashFunction(sha512.New, hex.EncodeToString)
Sha512Func is a function that computes the SHA512 hash of a given string and encodes it with hexadecimal digits.
Functions ¶
func Bcrypt ¶
Bcrypt computes a hash of the given string using the Blowfish cipher, returning a string in the Modular Crypt Format usually expected in the shadow password file on many Unix systems.
func RsaDecrypt ¶
RsaDecrypt decrypts an RSA-encrypted ciphertext, returning the corresponding cleartext.
Types ¶
This section is empty.