
Security News
New CVE Forecasting Tool Predicts 47,000 Disclosures in 2025
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
github.com/go-universal/cryptography
This library provides a comprehensive set of cryptographic utilities for hashing, encryption, and key management. It supports both symmetric and asymmetric cryptography, as well as various hashing algorithms.
To use this library, add it to your Go project:
go get github.com/go-universal/cryptography
Creates a new symmetric encryption driver.
func NewSymmetric(key SimpleKey, signer HashingAlgo) Cryptography
key, _ := cryptography.NewSimpleKey(cryptography.Simple32)
driver := cryptography.NewSymmetric(key, cryptography.SHA256)
data := []byte("my secret data")
// Encrypt
encrypted, _ := driver.EncryptBase64(data)
// Decrypt
decrypted, _ := driver.DecryptBase64(encrypted)
fmt.Println(string(decrypted)) // Output: my secret data
Creates a new asymmetric encryption driver with a private key.
func NewAsymmetric(key RSAKey, signer HashingAlgo) Cryptography
NewAsymmetricClient
Creates a new asymmetric encryption driver with a public key.
func NewAsymmetricClient(public *rsa.PublicKey, signer HashingAlgo) Cryptography
key, _ := cryptography.NewRSAKey(cryptography.RSA2048)
driver := cryptography.NewAsymmetric(*key, cryptography.SHA256)
data := []byte("my secret data")
// Encrypt
encrypted, _ := driver.EncryptBase64(data)
// Decrypt
decrypted, _ := driver.DecryptBase64(encrypted)
fmt.Println(string(decrypted)) // Output: my secret data
Creates a new Argon2 hasher.
func NewArgon2Hasher(
saltLength SimpleLength, keyLength uint32,
memory uint32, iterations uint32, parallelism uint8,
) Hasher
Creates a new bcrypt hasher.
func NewBcryptHasher(cost int) Hasher
Creates a new HMAC hasher.
func HMacHasher(key []byte, algo HashingAlgo) Hasher
password := []byte("my_password")
// Argon2
argon2Hasher := cryptography.NewArgon2Hasher(0, 0, 0, 0, 0)
hashed, _ := argon2Hasher.Hash(password)
valid, _ := argon2Hasher.Validate(hashed, password)
fmt.Println(valid) // Output: true
// bcrypt
bcryptHasher := cryptography.NewBcryptHasher(0)
hashed, _ = bcryptHasher.Hash(password)
valid, _ = bcryptHasher.Validate(hashed, password)
fmt.Println(valid) // Output: true
Generates a new random key of the specified length.
func NewSimpleKey(length SimpleLength) (SimpleKey, error)
Generates a new RSA private key of the specified length.
func NewRSAKey(length RSALength) (*RSAKey, error)
Parses an RSA private key from PKCS#1 or PKCS#8 format.
func ParsePrivateKey(key []byte, isPEM bool) (*RSAKey, error)
Parses an RSA public key from PKIX or PKCS#1 format.
func ParsePublicKey(key []byte, isPEM bool) (*rsa.PublicKey, error)
// Generate a new RSA key
rsaKey, _ := cryptography.NewRSAKey(cryptography.RSA2048)
// Export and parse the private key
privateKeyPEM, _ := rsaKey.PrivateKeyPEM(true)
parsedKey, _ := cryptography.ParsePrivateKey(privateKeyPEM, true)
// Export and parse the public key
publicKeyPEM, _ := rsaKey.PublicKeyPEM(true)
parsedPublicKey, _ := cryptography.ParsePublicKey(publicKeyPEM, true)
This project is licensed under the ISC License. See the LICENSE file for details.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.