English Title: signature verification process for digital signature of Byronsh's blog
Some of the bloggers have digital signatures.
The signature algorithm is SHA512+RSA4096, and only the text part is signed.
The public key of RSA4096 is as follows:
-----BEGIN PUBLIC KEY----- MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAnrJo0wOPcH+ZeAb+UsGh yHhPRiV4sox4aUf2SDHZVfCGUcpZJZQ5pi3QK0lNX4WuaBZ1HquhtU5s7uKqaJlf mb1gGCJOG17bHACJV143XR+T7VQe9UmBBp8gpBbEsdYg9+4TJCti8vmDvfz0meJF q9De5n9Uk2J2Gt2UQX+dpru8FnDmlI8AIt3eAyfJnY6XB4y9GymuXbyj6R238a6T 3udc7gK+50CgxVylBO5ANJ9YYDLkGv++9mAODlKXuE/xtG7XNXrTQ0f+NrlrRmDQ qCFmAYK8GdT0eKkkT4gHBah7wYEVpw9iOcHzVpajp7vsMe33qO3IpMTFpJ+TkZd9 H/7gQ6Hu5QPzv236Ym4nLAVtLOxx2iCN2cXT7cmkGas/9oDrYx1TdAW0VSk9PA2H KRKZOdy9XYNAN9HOTZcy8YfpLv5CN5OnA+Qpca3XHD3Xf2kYafV0hdMuhBY7EP4y yAxQt6Ug+9qWE4jJg5lh6jSbuMdfqO2a2JjZCh5Z4PrX+Cdnh6r1rV7lvSFZmyWY gsAuzGh2zip9FY/3Pdy+Y0Xb4PbvNWcc+R8LxF0PrFwwbiYRyC+tGPvUCQIyTHYd PMwNqcuxVh2X/WqcK6YVHUmlo6wDsJIMONDPzFTnM4VdhB1KgA5I0awzf6UuGBug X44OVTtMBuksYdiydc9wVokCAwEAAQ== -----END PUBLIC KEY-----
The following tools are tools for bloggers to generate signatures and verify signatures, based on javascript and html.
Steps to verify signatures (in windows):
1. Create a new text file with. txt as the suffix.
2 Copy the following code into a text file
3 Change the last. txt of the file to. html
4 double and file, open with browser
5 Copy the body of the blog without signature to the edit bar under Text. (Note: Do not copy the title and the signature at the end of the blog)
6 Copy the signature to the edit box under Signature
7. The public key has been added to the edit box under the "public key" by default and remains unchanged.
For verifying digital signatures, the "private key" does not work, and the edit box under the "private key" remains unchanged.
9. Click on the bottom button to "Verify Signature" and the verification results will pop up.
The purpose of signing a blog is to prevent some people from tampering with it at will, but there is no evidence to prove it. At the same time, I have been studying cryptography recently, which is also used in passing.
Possible problems
1 For the same blog, different browsers may copy different texts, which may lead to the failure of checking signatures. The digital signatures of this blog are generated and tested on Firefox browsing.
<!-- Copyright 2019 byronsh https://www.cnblogs.com/byronsh/ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <!DOCTYPE HTML> <html lang="zh-CN"> <head> <meta charset="utf-8"> <title>Digital Signature Generation/Verification</title> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jsrsasign/8.0.12/jsrsasign-all-min.js"></script> <script> /* * function generateSignature() * Function: Generate digital signatures */ function generateSignature(){ //1. Get the text that needs to be signed var plain_text = document.getElementById("input").value; //To reduce signature verification failures caused by page typesetting, delete all empty characters (spaces, newlines, tabs, etc.) plain_text_trim = plain_text.replace(/\s*/g, ""); //2. Signing with a private key //2.1 Access to Public Key var prk = document.getElementById("prk").value; var sign_key = KEYUTIL.getKey(prk); //2.2 Creating Signature Objects let signature = new KJUR.crypto.Signature({alg:"SHA512withRSA"}); //2.3 Initialize the key of the signature object and the text that needs to be signed signature.init(sign_key); signature.updateString(plain_text_trim); //2.4 Signature let a = signature.sign(); let sign = hextob64(a); //2.5 Update signatures to text boxes on Web pages document.getElementById("signature").value = sign + "\n------End Signature------" + getDateTime(); //3. Remind the user to sign document.getElementById("result").innerText = getDateTime() + " The signature was successful.\n" ; }; /* * function verifySignature() * Function: Verify Digital Signature */ function verifySignature(){ //1. Get the text and its signature that need to verify the digital signature //1.1 Getting Text var plain_text = document.getElementById("input").value; //To reduce signature verification failures caused by page typesetting, delete all empty characters (spaces, newlines, tabs, etc.) var plain_text_trim = plain_text.replace(/\s*/g, ""); //1.2 Get Signature var signature = document.getElementById("signature").value; signature = signature.replace(/\n------End Signature------.*/,""); //2. Verifying signatures with public keys //2.1 Access to Public Key var puk = document.getElementById("puk").value; var verify_key = KEYUTIL.getKey(puk); //2.2 Creating Signature Objects let signatureVf = new KJUR.crypto.Signature({alg:"SHA512withRSA"}); //2.3 Initialize the key of the signature object and the text that needs to be signed signatureVf.init(verify_key); signatureVf.updateString(plain_text_trim); //2.4 Verification Signature let b = signatureVf.verify(b64tohex(signature)); //3. Inform the user of the result of signature verification if(true == b){ alert("The signature is valid."); document.getElementById("result").innerHTML = "<p>" + getDateTime() + " autograph<b style='color:green'>effective<b></p>"; } else{ alert("The signature is invalid!!"); document.getElementById("result").innerHTML = "<p>" + getDateTime() + " autograph<b style='color:red'>invalid<b></p>"; } }; function getDateTime() { var now = new Date(); var year = now.getFullYear(); var month = now.getMonth()+1; var date = now.getDate(); var day = now.getDay(); var hour = now.getHours(); var minute = now.getMinutes(); var second = now.getSeconds(); var dateTime = year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second; return dateTime; }; </script> </head> <body> <div> <label for="input">text:</label><br> <textarea id="input" name="input" class=""></textarea><br> <label for="prk">private key:</label><br> <textarea id="prk" name="prk" class=""></textarea><br> <label for="puk">public key:</label><br> <!--The following is for validation byronsh Default Public Key for Digital Signature of Blog Articles--> <textarea id="puk" name="puk" class=""> -----BEGIN PUBLIC KEY----- MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAnrJo0wOPcH+ZeAb+UsGh yHhPRiV4sox4aUf2SDHZVfCGUcpZJZQ5pi3QK0lNX4WuaBZ1HquhtU5s7uKqaJlf mb1gGCJOG17bHACJV143XR+T7VQe9UmBBp8gpBbEsdYg9+4TJCti8vmDvfz0meJF q9De5n9Uk2J2Gt2UQX+dpru8FnDmlI8AIt3eAyfJnY6XB4y9GymuXbyj6R238a6T 3udc7gK+50CgxVylBO5ANJ9YYDLkGv++9mAODlKXuE/xtG7XNXrTQ0f+NrlrRmDQ qCFmAYK8GdT0eKkkT4gHBah7wYEVpw9iOcHzVpajp7vsMe33qO3IpMTFpJ+TkZd9 H/7gQ6Hu5QPzv236Ym4nLAVtLOxx2iCN2cXT7cmkGas/9oDrYx1TdAW0VSk9PA2H KRKZOdy9XYNAN9HOTZcy8YfpLv5CN5OnA+Qpca3XHD3Xf2kYafV0hdMuhBY7EP4y yAxQt6Ug+9qWE4jJg5lh6jSbuMdfqO2a2JjZCh5Z4PrX+Cdnh6r1rV7lvSFZmyWY gsAuzGh2zip9FY/3Pdy+Y0Xb4PbvNWcc+R8LxF0PrFwwbiYRyC+tGPvUCQIyTHYd PMwNqcuxVh2X/WqcK6YVHUmlo6wDsJIMONDPzFTnM4VdhB1KgA5I0awzf6UuGBug X44OVTtMBuksYdiydc9wVokCAwEAAQ== -----END PUBLIC KEY----- </textarea><br> <label for="signature">autograph:</label><br> <textarea id="signature" name="signature" class=""></textarea><br> </div> <div> <button id="btnGenSig" onclick="generateSignature()">Generate signature</button> <button id="btnVeriSig" onclick="verifySignature()">Verify signature</button> <p id="result">Please click the button "Verify Signature" or "Produce Signature"</p> </div> </body> </html>
Copyright Statement: This article is originally created by the blogger. It is allowed to be reproduced, but the original address must be indicated. The original blog: https://www.cnblogs.com/byronsh/p/blog-signature-verification.html
The digital signatures in this paper are as follows:
NoOKu/IqH7vLO0QS46e4Oe7VbhJJ2gUNy1BIC1FaptiJfrIHRlWj9m/nUvym63yndyc0nWlVKSvgOJ8ZOYPSXANlyJzKHs1wFrxeMOzr3/8YbkVIQeEuNw3ZYZZogE6xF2cdT9obub29/jMlaXCm6ASVyGXXkaNvDOzsOy20qqPlnHHmKFERHYWxF3RoXGprwhFpc/o5/hj4ZiwsnZjaO58NaaZUiTn2c838ZRdC032i5wrAmmhVJdwWwPPSFRI85FHJrz4UJKkcYyM/ZSkOHm2tBZDjgPIaDk5KLHLoxLc1k0+3JpfWq2H9LeS8Ju80+g1aP0pzKU0ieq4IXAQQt8IzuLvGXxZotUOZArBaZ0LQZNaIiltuZcfH/AZ3Expc/wzgZOb8o5C64yLO5ck7iybRzom1ieVzCIsYdBjy04OBRbQgR1mFw3r7RGuorNDfXOFqIsQdYMLvdwskJzIGNwWcr6gus/nTCpBsWumvAaW9BgVensBdsFxmuMevolX6OWMsEuQV4hshHH7tJHIeQZ6Xh5Q9rjdws/qQ7uVTEnGki+636R6utMAQ+Bvewf0O0sCa6mKUCjQkJJOllDGzuTw14BX/gh9R3XzYiCdO1obWKTlW+7MbY39WCj2g4+7XCPa+3k3fQgE9n/k/allZMg3eEdfPSeM+anD23mYY5fE=
------End Signature------2019-7-14