Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A functions wrapping of OpenSSL library for symmetric and asymmetric encryption and decryption.

License

NotificationsYou must be signed in to change notification settings

forgoer/openssl

Repository files navigation

Go Report CardDefaultCoverage StatusGodocRelease

A functions wrapping of OpenSSL library for symmetric and asymmetric encryption and decryption

Installation

The only requirement is theGo Programming Language

go get -u github.com/forgoer/openssl

Usage

AES

The length of the key can be 16/24/32 characters (128/192/256 bits)

AES-ECB:

src:= []byte("123456")key:= []byte("1234567890123456")dst ,_:=openssl.AesECBEncrypt(src,key,openssl.PKCS7_PADDING)fmt.Printf(base64.StdEncoding.EncodeToString(dst))// yXVUkR45PFz0UfpbDB8/ew==dst ,_=openssl.AesECBDecrypt(dst,key,openssl.PKCS7_PADDING)fmt.Println(string(dst))// 123456

AES-CBC:

src:= []byte("123456")key:= []byte("1234567890123456")iv:= []byte("1234567890123456")dst ,_:=openssl.AesCBCEncrypt(src,key,iv,openssl.PKCS7_PADDING)fmt.Println(base64.StdEncoding.EncodeToString(dst))// 1jdzWuniG6UMtoa3T6uNLA==dst ,_=openssl.AesCBCDecrypt(dst,key,iv,openssl.PKCS7_PADDING)fmt.Println(string(dst))// 123456

DES

The length of the key must be 8 characters (64 bits).

DES-ECB:

openssl.DesECBEncrypt(src,key,openssl.PKCS7_PADDING)openssl.DesECBDecrypt(src,key,openssl.PKCS7_PADDING)

DES-CBC:

openssl.DesCBCEncrypt(src,key,iv,openssl.PKCS7_PADDING)openssl.DesCBCDecrypt(src,key,iv,openssl.PKCS7_PADDING)

3DES

The length of the key must be 24 characters (192 bits).

3DES-ECB:

openssl.Des3ECBEncrypt(src,key,openssl.PKCS7_PADDING)openssl.Des3ECBDecrypt(src,key,openssl.PKCS7_PADDING)

3DES-CBC:

openssl.Des3CBCEncrypt(src,key,iv,openssl.PKCS7_PADDING)openssl.Des3CBCDecrypt(src,key,iv,openssl.PKCS7_PADDING)

RSA

openssl.RSAGenerateKey(bitsint,outio.Writer)openssl.RSAGeneratePublicKey(priKey []byte, outio.Writer)openssl.RSAEncrypt(src,pubKey []byte) ([]byte,error)openssl.RSADecrypt(src,priKey []byte) ([]byte,error)openssl.RSASign(src []byte,priKey []byte,hash crypto.Hash) ([]byte,error)openssl.RSAVerify(src,sign,pubKey []byte,hash crypto.Hash)error

HMAC-SHA

// Sha1 Calculate the sha1 hash of a stringSha1(str string) []byte// HmacSha1 Calculate the sha1 hash of a string using the HMAC methodHmacSha1(key string, data string) []byte// HmacSha1ToString Calculate the sha1 hash of a string using the HMAC method, outputs lowercase hexitsHmacSha1ToString(key string, data string) string// Sha256 Calculate the sha256 hash of a stringSha256(str string) []byte// HmacSha256 Calculate the sha256 hash of a string using the HMAC methodHmacSha256(key string, data string) []byte// HmacSha256ToString Calculate the sha256 hash of a string using the HMAC method, outputs lowercase hexitsHmacSha256ToString(key string, data string) string

License

This project is licensed under theApache 2.0 license.

Contact

If you have any issues or feature requests, please contact us. PR is welcomed.

About

A functions wrapping of OpenSSL library for symmetric and asymmetric encryption and decryption.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp