Skip to content

Go language implementation of symmetric encryption and asymmetric encryption algorithm. AES, DES, 3DES and RSA are supported

License

Notifications You must be signed in to change notification settings

agclqq/goencryption

Repository files navigation

goencryption

中文说明

install

go get github.com/agclqq/goencryption

summary

Supports symmetric encryption and asymmetric encryption algorithms.

symmetric encryption

  • aes
  • des
  • 3des

asymmetric encryption

  • rsa

usage

symmetric encryption

generic methods

EasyEncrypt(easyType, plaintext, key, iv)
EasyDecrypt(easyType, ciphertext, key, iv)

The parameter easyType should have a format like this:cryptoType/mode/padding or cryptoType/mode/padding/transcode

Note: Do not use AES and PKCS5 together. The block size of AES is 16, and the complement length needs to be 16, while the length of PKCS5 is 8. For example:

EasyEncrypt("des/CFB/Pkcs7/Base64", plaintext, key, iv)
EasyDecrypt("des/CFB/Pkcs7/Base64", ciphertext, key, iv)

EasyEncrypt("aes/CTR/Pkcs7", plaintext, key, iv)
EasyDecrypt("aes/CTR/Pkcs7", ciphertext, key, iv)

EasyEncrypt("3des/ECB/Pkcs5/Hex", plaintext, key, iv)
EasyDecrypt("3des/ECB/Pkcs5/Hex", ciphertext, key, iv)

The core approach to implementation is Encrypt() and Decrypt(). All other methods are facade.

about padding

  • noPadding: The data must be must be an integer multiple of the block
  • zeorPadding: It's going to fill in with zeros. If the original data ends in 0, there is a problem.
  • pkcs5Padding: The complement length is 8, which can be problematic in some cases
  • pkcs7Padding: Pkcs5Padding superset.Complement length is dynamic.

asymmetric encryption

Generate both private and public keys

GenKeys(bits)

Only the private key is generated

GenPrvKey(bits)

Generate a public key from a private key

GenPubKeyFromPrvKey(prvKey)

Public key encryption private key decryption

PubKeyEncrypt(pubKey, plainText)
PrvKeyDecrypt(prvKey, cipherText)

Private key signature, public key verification signature

PrvKeySign(prvKey, plainText, hash)
PubKeyVerifySign(pubKey, plainText, sign, hash)

About

Go language implementation of symmetric encryption and asymmetric encryption algorithm. AES, DES, 3DES and RSA are supported

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages