{"id":16800756,"url":"https://github.com/houseme/gocrypto","last_synced_at":"2025-07-25T18:41:56.022Z","repository":{"id":49831514,"uuid":"394558730","full_name":"houseme/gocrypto","owner":"houseme","description":"A general solution for commonly used crypt in golang","archived":false,"fork":false,"pushed_at":"2024-03-14T15:07:22.000Z","size":100,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-06T19:15:25.261Z","etag":null,"topics":["aes","base64","crypto","cryptography","decryption","des","des3","encryption","go","golang","hash","hex","rsa"],"latest_commit_sha":null,"homepage":"https://houseme.github.io/gocrypto/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/houseme.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":"houseme","issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":["https://paypal.me/houseme"]}},"created_at":"2021-08-10T07:10:31.000Z","updated_at":"2024-04-09T00:22:12.000Z","dependencies_parsed_at":"2023-12-18T10:52:46.054Z","dependency_job_id":"a97aed82-41b8-46cb-9008-152a5ca04370","html_url":"https://github.com/houseme/gocrypto","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/houseme/gocrypto","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/houseme%2Fgocrypto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/houseme%2Fgocrypto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/houseme%2Fgocrypto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/houseme%2Fgocrypto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/houseme","download_url":"https://codeload.github.com/houseme/gocrypto/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/houseme%2Fgocrypto/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267046788,"owners_count":24026906,"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","status":"online","status_checked_at":"2025-07-25T02:00:09.625Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","cryptography","decryption","des","des3","encryption","go","golang","hash","hex","rsa"],"created_at":"2024-10-13T09:34:57.230Z","updated_at":"2025-07-25T18:41:55.994Z","avatar_url":"https://github.com/houseme.png","language":"Go","funding_links":["https://liberapay.com/houseme","https://paypal.me/houseme"],"categories":[],"sub_categories":[],"readme":"# GoCrypto 使用说明\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/houseme/gocrypto.svg)](https://pkg.go.dev/github.com/houseme/gocrypto)\n[![GoCrypto CI](https://github.com/houseme/gocrypto/actions/workflows/go.yml/badge.svg)](https://github.com/houseme/gocrypto/actions/workflows/go.yml)\n[![GitHub](https://img.shields.io/github/license/houseme/gocrypto)](https://github.com/houseme/gocrypto)\n![GitHub go.mod Go version (branch)](https://img.shields.io/github/go-mod/go-version/houseme/gocrypto/main)\n\n## 特别说明\n\nbased on [GoRSA](https://github.com/farmerx/gorsa), [GoCrypt](https://github.com/yuchenfw/gocrypt) Optimized the following points for\npackaging:\n\n- Optimization of public and private keys requires registration and initialization in advance.\n- The encryption machine does not perform base64 processing, and avoids secondary encapsulation of base64 during\n  cross-program transfer or storage\n- The incoming return uses the string type uniformly to avoid conversion trouble\n- Supports RSAWithSHA1 and RSAWithSHA256 signature verification algorithms\n\n此版本新增了 AES、DES、3DES、HMAC、HASH 等常见加/解密及 hash 获取方式，结构作了些调整，由之前的版本更新到此版本时一定要注意引用方法包名的变化。AES/DES 块加密时，填充默认采用 PKCS7 padding(\n如果块大小为 64 位（8 字节）时，此时 PKCS7 与 PKCS5 结果一致).\n\n## get \u0026 import\n\n```go\ngo get -u -v github.com/houseme/gocrypto\n```\n\n\n\n## 使用方法\n\n### 1.构建需要加解密的类型 handle\n\n```go\n    handleRSA := rsa.NewRSACrypt(secretInfo) // RSA\n    handleDES := des.NewDESCrypt(key) // des\n    handle3DES := des.NewTripleDESCrypt(key) // 3des\n    handleAES := aes.NewAESCrypt(key) // aes\n    handleHash := hash.NewHash(hashType) // common hash\n    handleHMAC := hash.NewHMAC(hashType, key) // hmac\n```\n\n### 2.加密、解密、hash、hmac\n\n#### （1）加密\n\n加密指定字符串，并以指定编码格式输出结果\n\n```go\n    encrypt, err := handle.Encrypt(src) // des/3des/aes\n```\n\n#### （2）解密\n\n解密指定格式编码后的加密串，返回原字符串\n\n```go\n    decrypt, err := handle.Decrypt(src) // des/3des/aes\n```\n\n#### （3）hash/hmac\n\n哈希运算/密钥相关的哈希运算。\n\n```go\n    handle.Get([]byte(\"123456\"))// 输出 []byte\nhandle.EncodeToString([]byte(\"123456\"), gocrypto.HEX) // 输出为 hex 格式的字符串\n\n```\n\n## RSA 加密、解密、签名、验签\n\n### 1.设置公私钥信息\n\n```go\nsecretInfo := rsa.SecretInfo{\n    PublicKey:          \"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyoiAraTnAbCoq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ojz0ECgYEA5QzRObpU0CryfJ7qa97/USIKHbvl6PuQG9OLyUeP9bG0edidQhUrR4EZwjIl73O8CTJ0bB24wAKZZEOK3eJeqG/N0q+CiD83ygr8pSZzpE1xvqQp32IgXtgvm7/UmT8cfAp05Z3bF4jcA8uXwodBz4NsVGijlO78PsCooLsArM0CgYEA4lz5pXDEN3w5JwkbspLnUSUS738hne8YM0PchCaww+8sXLS9GLL2CHcvwh6Tv9Mee7r6SdbDI73x118y68WEDDhidiYZCLhXJN2v12ezJOMqH5m9wVJzQOGNv6kPV1EW1WlWxoJQGxCdzbZMLxtTbyTZe3+iAVG++8u6NWMV3dUCgYA1dm1rnQto321kGy+6Z/2OMXTNBeufGwDDDfilzZdTkNwASMhEAW7trLuXcV8bahcsymMUTUevQawOFBnYupq/lAEluSOtq5vZBAF+huAdLJptFiJT6rKFkM5j+z2jW3DJnyMz6UmXT7GTDTVqCWoaBqIFfbsY60NjXlK92YhJzQKBgQDWfQjktbSHasLw9RV0oPRklD+cBhfBgfOpZ+0En3CxR+j+MxhW1gSBQwZS5wxTIGXrEeHlo4UmUe5diExE0dRsi+ToVPM1qw6P1SuwbQd3tXSNmu0NyOWCnfblm/j4YNLFB1p9IK9s5dLRQKJxpG/ribw15FuK6n2QM5vOyIPIvQKBgE5PUzRUCCVsjKAxZOfaZQatMbSzAUSB3bNmUw+F3pDq8ibs6XXvtySowG2femlPDNL7mDMuUc9kYrtTFTQNrEsQGB55wBopX3UxzRjpXJoAQ/d+RPdrSJC7xJyu+URoFI6ae0I3bx1BzjctYU0Rv5DUh+j9leMH5N2S9vHb+vqu\",\n    PrivateKeyType:     gocrypto.PKCS1,\n    PrivateKeyDataType: gocrypto.Base64,\n    HashType:           gocrypto.SHA256,\n}\nhandle := rsa.NewRSACrypt(secretInfo)\n```\n\n### 加密、解密、签名、验签\n\n#### （1）RSA 加密 \n\n加密指定字符串，并以指定编码格式输出结果\n\n```go\nencrypt, err := handle.Encrypt(\"test\", gocrypto.HEX)\nif err != nil {\n    fmt.Println(\"encrypt error :\", err)\n    return\n}\nfmt.Println(\"encrypt data :\", encrypt)\n```\n\n#### （2）RSA 解密\n\n解密指定格式编码后的加密串，返回原字符串\n\n```go\ndecrypt, err := handle.Decrypt(encrypt, gocrypto.HEX)\nif err != nil {\n    fmt.Println(\"decrypt error :\", err)\n    return\n}\nfmt.Println(\"decrypt data :\", decrypt)\n```\n\n#### （3）RSA 签名\n\n以指定摘要算法签名，并以指定编码格式输出结果，仅适用于 RSA。\n\n```go\nsign, err := handle.Sign(\"test\", gocrypto.HEX)\nif err != nil {\n    fmt.Println(\"sign error :\", err)\n    return\n}\nfmt.Println(\"sign data :\", sign)\n```\n\n#### （4）RSA 验签\n\n验证字符串是否是以指定摘要算法编码的签名串的原始字符串，仅适用于 RSA。\n\n```go\nverifySign, err := handle.VerifySign(\"test\", sign, gocrypto.HEX)\nif err != nil {\n    fmt.Println(\"verifySign error :\", err)\n    return\n}\nfmt.Println(\"verifySign result :\", verifySign)\n```\n\n#### （5）RSA 私钥加密\n\n加密指定字符串，并以指定编码格式输出结果\n\n```go\nencrypt, err := handle.EncryptByPriKey(\"test\", gocrypto.HEX)\nif err != nil {\n    fmt.Println(\"encrypt error :\", err)\n    return\n}\nfmt.Println(\"encrypt data :\", encrypt)\n```\n\n#### （6）RSA 公钥解密\n\n解密指定格式编码后的加密串，返回原字符串\n\n```go\ndecrypt, err := handle.DecryptByPublic(encrypt, gocrypto.HEX)\nif err != nil {\n    fmt.Println(\"decrypt error :\", err)\n    return\n}\nfmt.Println(\"decrypt data :\", decrypt)\n```\n\n\n## License\n\nLicensed under either of Apache License, Version 2.0, [LICENSE](./LICENSE) at your option.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhouseme%2Fgocrypto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhouseme%2Fgocrypto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhouseme%2Fgocrypto/lists"}