Documentation ¶
Index ¶
- func ConvertSliceToUnsignedInteger(slice []byte, bigEndian bool) uint64
- func ConvertUnsignedIntegerToByteSlice(integer uint64, byteLength int, bigEndian bool) []byte
- func EncodePassword(hash crypto.Hash, password string, saltLength, iterationCount, keyLength int64, ...) (string, error)
- func EncodePasswordPBKDF1(hash crypto.Hash, password string, saltLength, iterationCount, keyLength int64) (string, error)
- func EncodePasswordPBKDF2(hash crypto.Hash, password string, saltLength, iterationCount, keyLength int64) (string, error)
- func GeneratePasswordString(salt []byte, iterationCount int64, encodedPassword []byte) string
- func GenerateRandomByte(min, max byte) (byte, error)
- func GenerateRandomInt64(min, max int64) (int64, error)
- func GenerateRandomPassword(minLength, maxLength int) (string, error)
- func GenerateRandomPasswordFromRunes(minLength, maxLength int, passwordRunes []rune) (string, error)
- func GenerateRandomSequence(length int) ([]byte, error)
- func GetPasswordParametersFromString(encodedPassword string) ([]byte, int64, []byte, error)
- func GetRandomRune(validRunes []rune) (rune, error)
- func PBKDF1(hash crypto.Hash, P []byte, S []byte, c int64, dkLen int64) ([]byte, error)
- func PBKDF2(hash crypto.Hash, P []byte, S []byte, c int64, dkLen int64) ([]byte, error)
- func VerifyPassword(hash crypto.Hash, password, encodedPassword string, kdf PBKDF) (bool, error)
- func VerifyPasswordPBKDF1(hash crypto.Hash, password, encodedPassword string) (bool, error)
- func VerifyPasswordPBKDF2(hash crypto.Hash, password, encodedPassword string) (bool, error)
- type PBKDF
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertSliceToUnsignedInteger ¶
ConvertByteSliceToUnsignedInteger converts a byte slice to an unsigned integer The slice parameter is the byte slice to be converted The bigEndian parameter indicates if the byte slice is big endian The integer is returned
func ConvertUnsignedIntegerToByteSlice ¶
ConvertUnsignedIntegerToByteSlice converts an unsigned integer to a byte slice The integer parameter is the integer to be converted The byteLength parameter is the length of the byte slice The bigEndian parameter indicates if the byte slice should be big endian The byte slice is returned
func EncodePassword ¶
func EncodePassword(hash crypto.Hash, password string, saltLength, iterationCount, keyLength int64, kdf PBKDF) (string, error)
EncodePassword encodes a password using the given algorithm The encoded password is returned as a string in the format: salt:iterationCount:hashedPassword(salt and hashedPassword are base64 encoded) The hash parameter is the hash function to be used(can be any crypto.Hash) The saltLength parameter is the length of the salt in bytes The iterationCount parameter is the number of iterations The keyLength parameter is the length of the derived key in bytes The kdf parameter is the function used to generate the password key it must have the PBKDF signature
func EncodePasswordPBKDF1 ¶
func EncodePasswordPBKDF1(hash crypto.Hash, password string, saltLength, iterationCount, keyLength int64) (string, error)
EncodePasswordPBKDF1 encodes a password using PBKDF1 algorithm The encoded password is returned in the format: salt:iterationCount:hashedPassword(salt and hashedPassword are base64 encoded) the hash parameter is the hash function to be used(can be any crypto.Hash) The saltLength parameter is the length of the salt in bytes The iterationCount parameter is the number of iterations The keyLength parameter is the length of the derived key in bytes
func EncodePasswordPBKDF2 ¶
func EncodePasswordPBKDF2(hash crypto.Hash, password string, saltLength, iterationCount, keyLength int64) (string, error)
EncodePasswordPBKDF2 encodes a password using PBKDF2 algorithm The encoded password is returned as a string in the format: salt:iterationCount:hashedPassword(salt and hashedPassword are base64 encoded) The hash parameter is the hash function to be used(can be any crypto.Hash) The saltLength parameter is the length of the salt in bytes The iterationCount parameter is the number of iterations The keyLength parameter is the length of the derived key in bytes
func GeneratePasswordString ¶
GeneratePasswordString generates a password string from the given parameters The salt parameter is the salt as a byte slice The iterationCount parameter is the iteration count The encodedPassword parameter is the encoded password as a byte slice The password string is returned in the format: salt:iterationCount:encodedPassword(salt and encodedPassword are base64 encoded)
func GenerateRandomByte ¶
GenerateRandomByte generates a random byte with value between min and max The min parameter is the minimum value of the random byte The max parameter is the maximum value of the random byte The random byte is returned
func GenerateRandomInt64 ¶
GenerateRandomInt64 generates a random int64 with value between min and max The min parameter is the minimum value of the random int64 The max parameter is the maximum value of the random int64 The random int64 is returned
func GenerateRandomPassword ¶
GenerateRandomPassword generates a random password The minLength parameter is the minimum length of the password The maxLength parameter is the maximum length of the password The password is returned as a string this function uses a built-in slice of runes for password generation to generate a password with a custom set of runes, use the GenerateRandomPasswordFromRunes function
func GenerateRandomPasswordFromRunes ¶
func GenerateRandomPasswordFromRunes(minLength, maxLength int, passwordRunes []rune) (string, error)
GenerateRandomPassword generates a random password The minLength parameter is the minimum length of the password The maxLength parameter is the maximum length of the password The password is returned as a string
func GenerateRandomSequence ¶
GenerateRandomSequence generates a random sequence of bytes with the given length. The length parameter is the length of the random sequence in bytes this function uses the crypto/rand package
func GetPasswordParametersFromString ¶
GetPasswordParametersFromString gets the password parameters from a password string the encodedPassword parameter is the password string the string must be in the format: salt:iterationCount:encodedPassword(salt and encodedPassword are base64 encoded) the salt, iterationCount and encodedPassword parameters are returned in this order the salt and encodedPassword parameters are byte slices
func GetRandomRune ¶
GetRandomRune gets a random rune from a slice of runes The validRunes parameter is the slice of runes to get the random rune from The random rune is returned
func PBKDF1 ¶
PBKDF1 is a function that implements the PBKDF1 algorithm It is based on the RFC8018(https://datatracker.ietf.org/doc/html/rfc8018) it implements the PBKDF function type
func PBKDF2 ¶
PBKDF2 is a function that implements the PBKDF2 algorithm It is based on the RFC8018(https://datatracker.ietf.org/doc/html/rfc8018) it implements the PBKDF function type
func VerifyPassword ¶
VerifyPassword checks if a password matches an encoded password The encoded password must be in the format: salt:iterationCount:hashedPassword(salt and hashedPassword are base64 encoded) The hash parameter is the hash function to be used(can be any crypto.Hash) The password parameter is the password to be checked The encodedPassword parameter is the encoded password The function parameter is the function that has been used to generate the encoded password it must have the PBKDF signature
func VerifyPasswordPBKDF1 ¶
VerifyPasswordPBKDF1 checks if a password matches an encoded password The encoded password must be in the format: salt:iterationCount:hashedPassword(salt and hashedPassword are base64 encoded) The hash parameter is the hash function to be used(can be any crypto.Hash) The password parameter is the password to be checked The encodedPassword parameter is the encoded password
func VerifyPasswordPBKDF2 ¶
VerifyPasswordPBKDF2 checks if a password matches an encoded password The encoded password must be in the format: salt:iterationCount:hashedPassword(salt and hashedPassword are base64 encoded) The hash parameter is the hash function to be used(can be any crypto.Hash) The password parameter is the password to be checked The encodedPassword parameter is the encoded password
Types ¶
type PBKDF ¶
PBKDF is the general signature for a password-based key derivation function. hash: the hash function to be used(can be any crypto.Hash) P: the password(as a byte slice) S: the salt(as a byte slice) c: the iteration count dkLen: the byte length of the derived key returns: DK, the derived key or an error if any the functions PBKDF1 and PBKDF2 of this package implement this function