{"id":207520,"date":"2025-07-08T11:00:49","date_gmt":"2025-07-08T03:00:49","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207520\/"},"modified":"2025-07-08T11:00:49","modified_gmt":"2025-07-08T03:00:49","slug":"golang-%e7%9b%b8%e5%bd%93%e4%ba%8e-java-%e7%9a%84-sha256withrsa","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207520\/","title":{"rendered":"Golang \u76f8\u5f53\u4e8e Java \u7684 SHA256withRSA"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>Golang \u76f8\u5f53\u4e8e Java \u7684 SHA256withRSA<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-23 11:39:20<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u4e00\u5206\u8015\u8018\uff0c\u4e00\u5206\u6536\u83b7\uff01\u65e2\u7136\u6253\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aGolang \u76f8\u5f53\u4e8e Java \u7684 SHA256withRSA\u300b<\/span>\uff0c\u5c31\u575a\u6301\u770b\u4e0b\u53bb\u5427\uff01\u6587\u4e2d\u5185\u5bb9\u5305\u542b<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9&#8230;\u5e0c\u671b\u4f60\u80fd\u5728\u9605\u8bfb\u672c\u6587\u540e\uff0c\u80fd\u771f\u771f\u5b9e\u5b9e\u5b66\u5230\u77e5\u8bc6\u6216\u8005\u5e2e\u4f60\u89e3\u51b3\u5fc3\u4e2d\u7684\u7591\u60d1\uff0c\u4e5f\u6b22\u8fce\u5927\u4f6c\u6216\u8005\u65b0\u4eba\u670b\u53cb\u4eec\u591a\u7559\u8a00\u8bc4\u8bba\uff0c\u591a\u7ed9\u5efa\u8bae\uff01\u8c22\u8c22\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u662f\u5426\u6709 Java \u7684 <code>java.security.Signature<\/code> \u7684 SHA256withRSA \u7684 Golang \u7b49\u6548\u9879\uff1f\u4e00\u4e9b\u7814\u7a76\u8868\u660e\uff0c\u6211\u65e0\u6cd5\u7b80\u5355\u5730\u8ba1\u7b97 SHA256 \u54c8\u5e0c\u503c\uff0c\u7136\u540e\u4f7f\u7528 RSA \u5bf9\u5176\u8fdb\u884c\u7b7e\u540d\u3002<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u5f04\u6e05\u695a\u5982\u679c\u6709\u4eba\u5076\u7136\u53d1\u73b0\u4e86\u540c\u6837\u7684\u95ee\u9898\uff0c\u8fd9\u5c31\u662f\u5b83\u5728 go \u4e2d\u7684\u5de5\u4f5c\u539f\u7406<\/p>\n<pre>func main() {\n    privateKey := loadPrivateKey()\n    h := sha256.New()\n    h.Write([]byte(`your message`))\n    d := h.Sum(nil)\n\n    signature, err := rsa.SignPKCS1v15(rand.Reader, privateKey, crypto.SHA256, d)\n    if err != nil {\n        panic(err)\n    }\n\n    fmt.Printf(\"Signature in byte: %v\\n\\n\", signature)\n\n    encodedSig := base64.StdEncoding.EncodeToString(signature)\n\n    fmt.Printf(\"Encoded signature: %v\\n\\n\", encodedSig)\n}<\/pre>\n<p>\u4eca\u5929\u5173\u4e8e\u300aGolang \u76f8\u5f53\u4e8e Java \u7684 SHA256withRSA\u300b\u7684\u5185\u5bb9\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\u4e86\uff0c\u662f\u4e0d\u662f\u5b66\u8d77\u6765\u4e00\u76ee\u4e86\u7136\uff01\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u5185\u5bb9\u8bf7\u5173\u6ce8\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-207520","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207520","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=207520"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207520\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207520"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207520"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207520"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}