Added the SHA256 algorithm.

main
Tylan Tyson 12 months ago
parent 4b51809ce9
commit 0c185d23a5

@ -14,6 +14,7 @@ GCL is a Go library designed to offer a robust collection of cryptographic algor
GCL offers support for a diverse range of cryptographic algorithms, ensuring that your cryptographic requirements are comprehensively addressed. Our library includes: GCL offers support for a diverse range of cryptographic algorithms, ensuring that your cryptographic requirements are comprehensively addressed. Our library includes:
- [X] BLAKE2 - [X] BLAKE2
- [X] SHA256
## Installation ## Installation

@ -0,0 +1,21 @@
package sha256
import (
// Standard
"crypto/sha256"
"crypto/subtle"
)
// Check Hash
func (Algorithm) CheckHash(data []byte, hashToCheck []byte) (bool, error) {
// Hasher
hasher := sha256.New()
// Write To Hasher
_, err := hasher.Write(data)
// Handle Error
if err != nil {
return false, err
}
// Return Hash
return subtle.ConstantTimeCompare(hasher.Sum(nil), hashToCheck) == 1, err
}

@ -0,0 +1,20 @@
package sha256
import (
// Standard
"crypto/sha256"
)
// Hash
func (Algorithm) Hash(data []byte) ([]byte, error) {
// Hasher
hasher := sha256.New()
// Write To Hasher
_, err := hasher.Write(data)
// Handle Error
if err != nil {
return []byte(""), err
}
// Return Hash
return hasher.Sum(nil), err
}

@ -0,0 +1,10 @@
package sha256
// Algorithm
type Algorithm struct{}
// New
func New(size int) Algorithm {
// Return Algorithm
return Algorithm{}
}
Loading…
Cancel
Save