Algorithm | hashvalue size | collision | use cases |
---|---|---|---|
SHA-0 | 160 bits | o | x |
SHA-1 | 160 bits | o | git, file verification |
SHA-2 SHA-3 | 224 256 384 512 bits | - | blockchain, SSL certificate, user info |
SHA-2 is vulnerable to brute-force attack because the operation speed using GPU is very fast.
bcrpyt
PBKDF2
Comparison of AES and DES
. | AES | DES |
---|---|---|
key length | 56 bits | 128/192/256 bits |
block size | 64 bits | 128 bits |
known attacks | No known attack | Brute-force, Linear crypt- analysis |
security | insecure | secure |
brute force | 2^55 | 2^127 (in 128 bits) |
👉 Regulations
👉 Terms
digest means hash value
salt is a random data that is used as an additional input to a one-way hash function.
salting makes rainbow table meaningless using salt.
key strectching is used to make a relatively insecure value, such as password more secure against a brute force attack by increasing the time it takes. (This is to repeat creating a digest using the created digest.)
👉 ETC
scrypt, HMAC, argon2
It can check whether the file is corrupted or not with the original file and the hash value.
import (
"crypto/sha256"
"encoding/hex"
)
import "crypto/md5
f, err := os.Open("/Users/gom/image.png")
if err != nil {
log.Fatal(err)
}
defer f.Close()
h := md5.New()
if _, err := io.Copy(h, f); err != nil {
log.Fatal(err)
}
fmt.Printf("%w\n", h.Sum(nil))
=> d11d54a4dd7328dd37eb21f8985ca9c7
SHA2 "crypto/sha256" | "crypto/sha512"
hash algorithms as defined in FIPS 180-4.
SHA3 "golang.org/x/crypto/sha3"
hash algorithms as defined by FIPS-202.
import (
"crypto/rand"
"crypto/sha256"
"crypto/sha512"
"encoding/hex"
"encoding/base64"
)
// 1
f, err := os.Open("/Users/gom/image.png")
if err != nil {
log.Fatal(err)
}
defer f.Close()
h := sha256.New()
if _, err := io.Copy(h, f); err != nil {
log.Fatal(err)
}
fmt.Printf("%x\n", h.Sum(nil))
// 2
hh := sha256.New()
hh.Write([]byte("abcd1234!@#$"))
hashValue := hex.EncodeToString(h.Sum(nil))
fmt.Println(hashValue)
// 3
salt := make([]byte, 16)
_, err := rand.Read(salt)
if err != nil {
log.Fatal(err)
}
hhh := sha512.New()
hhh.Write(append([]byte("abcd1234!!"), salt...))
r := base64.URLEncoding.EncodeToString(hhh.Sum(nil))
fmt.Println(r)
import (
"golang.org/x/crypto/bcrypt"
)
// hash password
password := "abcd1234!!"
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 10)
// check password
err := bcrypt.CompareHashAndPassword([]byte(bytes), []byte(password))
Regulations
https://www.pipc.go.kr/np/cop/bbs/selectBoardArticle.do?bbsId=BS217&mCode=D010030000&nttId=7041#LINK
https://blog.naver.com/16954/222681910557
Library
https://pkg.go.dev/crypto/md5
https://pkg.go.dev/crypto/sha256
https://pkg.go.dev/crypto/sha512
https://pkg.go.dev/golang.org/x/crypto/sha3
https://github.com/golang/crypto
https://pkg.go.dev/golang.org/x/crypto/bcrypt