{"id":24650841,"url":"https://github.com/ggdream/crypto","last_synced_at":"2025-08-17T16:37:31.268Z","repository":{"id":52946920,"uuid":"280443238","full_name":"ggdream/crypto","owner":"ggdream","description":"Golang的加解密、签验名的二次封装库。RSA、AES和ECC加解密、签名验签。生成随机秘钥key的函数。哈希函数MD5、SHA256等，hex和base64编解码","archived":false,"fork":false,"pushed_at":"2021-01-21T12:45:47.000Z","size":33,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-21T08:13:22.812Z","etag":null,"topics":["aes","base64","crypto","ecc","golang","hex","ptr","rsa"],"latest_commit_sha":null,"homepage":"https://golang.google.cn/pkg/crypto","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ggdream.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-17T14:18:39.000Z","updated_at":"2024-05-29T18:19:12.000Z","dependencies_parsed_at":"2022-08-28T03:12:47.409Z","dependency_job_id":null,"html_url":"https://github.com/ggdream/crypto","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ggdream%2Fcrypto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ggdream%2Fcrypto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ggdream%2Fcrypto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ggdream%2Fcrypto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ggdream","download_url":"https://codeload.github.com/ggdream/crypto/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235614247,"owners_count":19018405,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aes","base64","crypto","ecc","golang","hex","ptr","rsa"],"created_at":"2025-01-25T18:16:50.183Z","updated_at":"2025-01-25T18:16:50.985Z","avatar_url":"https://github.com/ggdream.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Golang的加解密、签验名的二次封装库\n\n## 一、介绍\n\n！！😫\n。😘😘\n\n## 二、安装\n\n~~~shell\ngo get -u github.com/ggdream/crypto\n~~~\n\n## 三、例子\n\n~~~go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/ggdream/crypto/rsa\"\n)\n\n\nfunc main() {\n\tpri, pub := rsa.GenerateKey(1024)\n    \n\tcipher := rsa.Encrypt([]byte(\"我喜欢你\"), pub)\n\tfmt.Println(cipher)\n    \n\tplaint := rsa.Decrypt(cipher, pri)\n\tfmt.Println(string(plaint))\n}\n~~~\n\n## 四、函数签名\n\n### 1. RSA\n\n~~~go\n// package: github.com/ggdream/crypto/rsa\n\n\n// 操作秘钥\nfunc GenerateKey(bits int) (*rsa.PrivateKey, *rsa.PublicKey)\nfunc GenerateHexKey(bits int) (string, string)\n\nfunc GetEN(publicKey *rsa.PublicKey) (string, string)\nfunc SetEN(exp, mod string) *rsa.PublicKey\n\nfunc GetPrivateKey(hexKey string) *rsa.PrivateKey\nfunc GetPublicKey(hexKey string) *rsa.PublicKey\n\nfunc SetPrivateKeyToPem(privateKey *rsa.PrivateKey) string\nfunc SetPublicKeyToPem(publicKey *rsa.PublicKey) string\nfunc GetPrivateKeyFromPem(privateKeyPem string) *rsa.PrivateKey\nfunc GetPublicKeyFromPem(publicKeyPem string) *rsa.PublicKey\n\n\n// 加密解密\nfunc Encrypt(text []byte, publicKey *rsa.PublicKey) []byte\nfunc Decrypt(text []byte, privateKey *rsa.PrivateKey) []byte\n\n// 签名验签\nfunc Sign(text []byte, privateKey *rsa.PrivateKey) ([]byte, error)\nfunc Verify(text, sign []byte, publicKey *rsa.PublicKey) bool\n~~~\n\n### 2. ECC\n\n~~~go\n// package: github.com/ggdream/crypto/ecc\n\n\n// 操作秘钥\nfunc GenerateKey(model int) (*ecdsa.PrivateKey, *ecdsa.PublicKey)\nfunc GenerateKeyEth() (*ecies.PrivateKey, *ecies.PublicKey)\n\nfunc SetPrivateKeyToPem(privateKey *ecdsa.PrivateKey) string\nfunc SetPublicKeyToPem(publicKey *ecdsa.PublicKey) string\nfunc GetPrivateKeyFromPem(privateKeyPem string) *ecdsa.PrivateKey\nfunc GetPublicKeyFromPem(publicKeyPem string) *ecdsa.PublicKey\n\n\n// 加密解密\nfunc Encrypt(text []byte, publicKey  *ecies.PublicKey) []byte\nfunc Decrypt(text []byte, privateKey *ecies.PrivateKey) []byte\n\n// 签名验签\nfunc Sign(text []byte, privateKey *ecdsa.PrivateKey) ([]byte, []byte)\nfunc Verify(text, rBytes, sBytes []byte, publicKey *ecdsa.PublicKey) bool\n~~~\n\n### 3. AES\n\n~~~go\n// package: github.com/ggdream/crypto/aes\n\n\n// 填充方式（AES并没有64位的块, 如果采用PKCS5, 那么实质上就是采用PKCS7。所以我封装的时候直接让PKCS7函数等上PKCS5函数）\nfunc ZeroPadding(text []byte, blockSize int) []byte\nfunc ZeroUnPadding(text []byte) []byte\n\nfunc PKCS5Padding(text []byte, blockSize int) []byte\nfunc PKCS5UnPadding(text []byte) []byte\n\nvar PKCS7Padding func(text []byte, blockSize int) []byte = PKCS5Padding\nvar PKCS7UnPadding func(text []byte) []byte = PKCS5UnPadding\n\n\n// 加密解密（CBC模式。里面使用的填充方式是PKCS5(同时也可以被看做使用的是PKCS7)）\nfunc Encrypt(text, key, iv []byte) []byte\nfunc Decrypt(text, key, iv []byte) []byte\n~~~\n\n### 4. KEY\n\n~~~go\n// package: github.com/ggdream/crypto/key\n\n\n// 依于MD5生成秘钥\nfunc Gen16ByMD5() []byte\n\n// 依于随机数生成秘钥\nfunc GenByRand(bits int) []byte\nfunc Gen16ByRand() []byte\nfunc Gen32ByRand() []byte\nfunc Gen64ByRand() []byte\n~~~\n\n### 5. HASH\n\n~~~go\n// file: github.com/ggdream/crypto/hashers.go\nconst (\n\tDefineMD5\t\t\t= \"md5\"\n\tDefineSHA1\t\t\t= \"sha1\"\n\tDefineSHA224\t\t= \"sha224\"\n\tDefineSHA256\t\t= \"sha256\"\n\tDefineSHA384\t\t= \"sha384\"\n\tDefineSHA512\t\t= \"sha512\"\n\tDefineSHA3224\t\t= \"sha3-224\"\n\tDefineSHA3256\t\t= \"sha3-256\"\n\tDefineSHA3384\t\t= \"sha3-384\"\n\tDefineSHA3512\t\t= \"sha3-512\"\n)\n\ntype Hasher struct\nfunc Hash(algorithm string, data []byte) (string, error)\nfunc (h *Hasher) GetHasher() hash.Hash\nfunc (h *Hasher) ToBytes() ([]byte, error)\nfunc (h *Hasher) ToBase64() (string, error)\nfunc (h *Hasher) ToHex() (string, error)\nfunc FileMD5(file io.Reader) string\n~~~\n\n### 6. encode/decode\n\n~~~go\n// file: github.com/ggdream/crypto/coders.go\n\n\n// Base64编解码\nfunc EnBase64(src []byte) string\nfunc DeBase64(src string) []byte\n\n// 16进制编解码\nfunc EnHex(src []byte) string\nfunc DeHex(src string) []byte\n~~~\n\n### 7. byte[]/string\n\n~~~go\n// file: github.com/ggdream/crypto/ptr.go\n// to change struct by using ptr.\n\n\n// byte[]转string\nfunc SliceToString(data []byte) string\n\n// string转byte[]\nfunc StringToSlice(data string) []byte\n~~~\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fggdream%2Fcrypto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fggdream%2Fcrypto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fggdream%2Fcrypto/lists"}