password

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2023 License: MIT Imports: 16 Imported by: 0

README

Go Password

Go

A module that implement hashing and (encrypt/decrypt) algorithms

Current supported algorithms :

  • Hash
    • MD5
    • SHA1
    • SHA256
    • SHA512

Authors

Installation Guidelines

Go get

  go get -u github.com/nandanurseptama/go-password

Import

  import "github.com/nandanurseptama/go-password"

Examples

import "github.com/nandanurseptama/go-password"

plainString := "wkwk"

# return `0bef1939b3c02eea4b89f1a8247419cf`, nil
md5HashedString, err := HashMethodMD5.Hashing(plainString)

License

This code is licensed under the MIT license.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	HashMethodMD5    *MD5HashPassword
	HashMethodSHA1   *SHA1HashPassword
	HashMethodSHA256 *SHA256HashPassword
	HashMethodSHA512 *SHA512HashPassword
)

Functions

This section is empty.

Types

type AESEncryptPassword added in v0.2.0

type AESEncryptPassword struct {
	SecretKey string
}

func (AESEncryptPassword) Decrypt added in v0.2.0

func (r AESEncryptPassword) Decrypt(encryptedString string) (*string, error)

Decrypt string with AES-GCM

Will encrypt plain string to encryted string in (hex format)

if success will return encrypted string (hex format) and nil error

if fail will return encrypted string nil and error

func (AESEncryptPassword) Encrypt added in v0.2.0

func (r AESEncryptPassword) Encrypt(plainString string) (*string, error)

Encrypt string with AES-GCM

Will encrypt plain string to encryted string in (hex format)

if success will return encrypted string (hex format) and nil error

if fail will return encrypted string nil and error

type EncryptPassword

type EncryptPassword interface {
	Encrypt(plainString string, key string) (*string, error)
	Decrypt(encryptedString string, key string) (*string, error)
}

type HashPassword

type HashPassword interface {
	// abstract function of hashing
	// will be implemented on each hashing algorithm
	Hashing(plainString string) (*string, error)
}

HashPassword interface of Hash Algorithm

type MD5HashPassword

type MD5HashPassword struct {
}

MD5HashPassword implements hashing password with MD5 algorithm

func (MD5HashPassword) Hashing

func (h MD5HashPassword) Hashing(plainString string) (*string, error)

Hashing plain string to hashed string with MD5 algorithm

will return nil string and error if hashing fail

will return hashed string and nil error is hashing success

type RSAEncryptPassword added in v0.2.0

type RSAEncryptPassword struct {
	Pk string
}

RSAEncryptPassword is implementation of RSA Encryption

func (RSAEncryptPassword) Decrypt added in v0.2.0

func (r RSAEncryptPassword) Decrypt(encryptedString string) (*string, error)

Decrypt

Will Decrypt encrypted string (hex format) to plain string

if success will return plain string and nil error

if fail will return nil string and error

func (RSAEncryptPassword) Encrypt added in v0.2.0

func (r RSAEncryptPassword) Encrypt(plainString string) (*string, error)

Encrypt

Will encrypt plain string to encryted string in (hex format)

if success will return encrypted string (hex format) and nil error

if fail will return encrypted string nil and error

type SHA1HashPassword

type SHA1HashPassword struct {
}

SHA1HashPassword implements hashing password with SHA1 algorithm

func (SHA1HashPassword) Hashing

func (h SHA1HashPassword) Hashing(plainString string) (*string, error)

Hashing plain string to hashed string with SHA1 algorithm

will return nil string and error if hashing fail

will return hashed string and nil error is hashing success

type SHA256HashPassword

type SHA256HashPassword struct {
}

SHA256HashPassword implements hashing password with SHA256 algorithm

func (SHA256HashPassword) Hashing

func (h SHA256HashPassword) Hashing(plainString string) (*string, error)

Hashing plain string to hashed string with SHA256 algorithm

will return nil string and error if hashing fail

will return hashed string and nil error is hashing success

type SHA512HashPassword

type SHA512HashPassword struct {
}

SHA512HashPassword implements hashing password with SHA256 algorithm

func (SHA512HashPassword) Hashing

func (h SHA512HashPassword) Hashing(plainString string) (*string, error)

Hashing plain string to hashed string with SHA512 algorithm

will return nil string and error if hashing fail

will return hashed string and nil error is hashing success

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL