{"id":42500805,"url":"https://github.com/melf-xyzh/go-rsa","last_synced_at":"2026-01-28T13:06:03.021Z","repository":{"id":37283824,"uuid":"500689572","full_name":"melf-xyzh/go-rsa","owner":"melf-xyzh","description":"Go语言常用的rsa方法封装，RSA加密解密，sha1withrsa签名验签，PFX证书读取","archived":false,"fork":false,"pushed_at":"2022-06-08T01:39:23.000Z","size":15,"stargazers_count":12,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-06-21T18:50:28.565Z","etag":null,"topics":["decrypt","encrypt","go","golang","pfx","rsa","sha1withrsa","sign","verify"],"latest_commit_sha":null,"homepage":"","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/melf-xyzh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-06-07T04:33:20.000Z","updated_at":"2024-04-08T03:13:03.000Z","dependencies_parsed_at":"2022-08-19T01:50:50.855Z","dependency_job_id":null,"html_url":"https://github.com/melf-xyzh/go-rsa","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/melf-xyzh/go-rsa","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/melf-xyzh%2Fgo-rsa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/melf-xyzh%2Fgo-rsa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/melf-xyzh%2Fgo-rsa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/melf-xyzh%2Fgo-rsa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/melf-xyzh","download_url":"https://codeload.github.com/melf-xyzh/go-rsa/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/melf-xyzh%2Fgo-rsa/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28845816,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T13:02:32.985Z","status":"ssl_error","status_checked_at":"2026-01-28T13:02:04.945Z","response_time":57,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["decrypt","encrypt","go","golang","pfx","rsa","sha1withrsa","sign","verify"],"created_at":"2026-01-28T13:06:02.947Z","updated_at":"2026-01-28T13:06:03.014Z","avatar_url":"https://github.com/melf-xyzh.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## go-rsa\n\n### 安装\n\n```bash\ngo get github.com/melf-xyzh/go-rsa\n```\n\n### 使用方法\n\n### sha1withrsa\n\n##### 签名\n\n```go\n// 需要签名的文本\ncontext := \"helloworld\" \n// 签名\nsign, err := sha1withrsa.Sign(privateKey, context)\nif err != nil {\n\tlog.Fatalln(err)\n}\nfmt.Println(sign)\n```\n\n##### 验签\n\n```go\n// 验签\nverify, err := sha1withrsa.RSAVerify(publicKey, context, sign)\nif err != nil {\n\treturn\n}\nfmt.Println(verify)\n```\n\n### 加密 / 解密\n\n```go\n// 加密\nencrypt, err := myrsa.RsaEncrypt(publicKey, content)\nif err != nil {\n\treturn\n}\n// 解密\ndata, err := myrsa.RsaDecrypt(privateKey,encrypt)\nif err != nil {\n\treturn\n}\n```\n\n### 生成读取公私钥文件（pem格式 / PKCS1）\n\n```go\n// 生成公钥文件（pem格式）\nerr = myrsa.CreatePrivatePem(privateKey, \"\")\nif err != nil {\n\tlog.Fatal(err)\n}\n// 读取私钥文件（pem格式）\nerr = myrsa.CreatePublicPem(publicKey, \"\")\nif err != nil {\n\tlog.Fatal(err)\n}\n// 读取私钥文件（pem格式）\nprivateKey, err = myrsa.ReadPrivatePem(\"cert/private.pem\")\nif err != nil {\n    log.Fatal(err)\n}\n// 读取公钥文件（pem格式）\npublicKey, err = myrsa.ReadPublicPem(\"cert/public.pem\")\nif err != nil {\n    log.Fatal(err)\n}\n```\n\n### 生成读取公私钥文件（ec格式 / PKCS8）\n\n```go\n// 生成私钥文件（ec格式）\nerr = myrsa.CreatePrivateEC(privateKey, \"cert/private.key\")\nif err != nil {\n\tlog.Fatal(err)\n}\n// 生成公钥文件（ec格式）\nerr = myrsa.CreatePublicEC(publicKey, \"cert/public.key\")\nif err != nil {\n\tlog.Fatal(err)\n}\n// 读取私钥文件（ec格式）\nprivateKey, err = myrsa.ReadPrivateEC(\"cert/private.key\")\nif err != nil {\n\tlog.Fatal(err)\n}\n// 读取公钥文件（ec格式）\npublicKey, err = myrsa.ReadPublicEC(\"cert/public.key\")\nif err != nil {\n\tlog.Fatal(err)\n}\n```\n\n### 生成证书文件（CA）\n\n```go\n// 生成CA证书\nerr = myrsa.CreateCertificate(publicKey, privateKey, \"cert/ca/\")\nif err != nil {\n\tlog.Fatal(err)\n}\n// 导入CA证书\ncertificate, err := myrsa.LoadCertificate(\"cert/ca/ca.crt\")\nif err != nil {\n    log.Fatal(err)\n}\n```\n\n### PFX证书\n\n```go\n// 从PFX证书中解析公私钥\nprivateKey, publicKey, err := pfx.GetPublicAndPrivateKeyFromPfx(\"zhengshu.pfx\", \"123456\")\nif err != nil {\n\treturn\n}\npfx.PrintPublicKey(publicKey)\npfx.PrintPrivateKey(privateKey)\n```\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmelf-xyzh%2Fgo-rsa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmelf-xyzh%2Fgo-rsa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmelf-xyzh%2Fgo-rsa/lists"}