用梨子来理解rsa的验签过程

08-27 10:01:39.428 17148 17148 I MainActivity: test_Btn_1 click 3
08-27 10:01:39.434 17148 17148 E RSAUtil : loadKeyFromAssets: key = MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDLiFX9YTy5sziJZjliEoAbb1RqrdadDkCHvs2b41AxD1bqrhE4SGsQnw2VXr9uzckZoQReNfSV9N3ci4cA+ZmRR9Y959045Zj8Ot6TNkV7ejiC7BBirPoKXEhWT9y9BawQFh92ekioxhNrVuxpIctn1HQczqTJvrayk1mvRaCZ/zqmlwZezFHy7yhNl5ruHUf9lemRfpYL5/OpBkyiuZzQWZv7YzUBYMx/tJGEyRLLpkq3FWpHqxxAT11hkh7G4qmCoCPYBf9PG/EFargZz6wozs2N/JD3QyiE5Fpih2NvSTcm25MrR8rw8xGiAco4SEe98W8ll9SNzEal6fKRx+ZFAgMBAAECggEBAKVmE8snG/wk4sr1oahLNIQXAtj2kDNtg49MxTXrkh1sQ8vOzPuaDjehqZ47MwJOhSAos64D1tGN/kXdtUZbkCp54GbKaAJ2ws4m4P1s2yYu+oGaaO5nd4K336kUmWOammswLz1OvoE5BkryhoghCHVGN125qDyymTGhgP5obMz3IZ6/8XDJkFTHEQs5TyKCs6rwf0i8gRHZvg4+ApKKoawS27LkeGiJ/wVw2kgG668wd2zvRJgAMEui0tS9c7YYBF0mSoF/RgqwxKycA/+HVfKGphHGn2PkUWqJbG0eSMySDCVR7C8xhF5JzBCrbkfh2t8FmC8yKgpb4oeKx+aCS/kCgYEA/X0e7SibE9JBfjmWfRsaQphqUZuKky7yM4FYy7WF+Ibf2q+GUtXdUCW6iC4TLgfIb4yFe+YxoufeMgxMut8KLPVHSnpn8bRZNb1pf5bORhEo/hHfz2CYFLtDX81XLHsE4s8spGmOS9kHnRzK/MhgI7I/VpXFBp1ZgT85ihpxoCsCgYEAzYyFGtBLDzO+uD9F/IiGzZv8cpFPQ6NBXxirrsfbVwncKSctNVKUzUp4ecF0NJ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8XCC/9g1txaeQuDasA6u56Dqss6m6CTv0bC4dyXHVRQ8emFH6IQEA+CEtXUKbF0HSNrPcNyPNgTPZ41+GgvPUcKGBakutN18xYom+JVr1bjqoT6yd22INnwISC1Wpry/9nKLcRBekjY=
08-27 10:01:39.442 17148 17148 E RSAUtil : loadKeyFromAssets: key = MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAy4hV/WE8ubM4iWY5YhKAG29Uaq3WnQ5Ah77Nm+NQMQ9W6q4ROEhrEJ8NlV6/bs3JGaEEXjX0lfTd3IuHAPmZkUfWPefdOOWY/DrekzZFe3o4guwQYqz6ClxIVk/cvQWsEBYfdnpIqMYTa1bsaSHLZ9R0HM6kyb62spNZr0Wgmf86ppcGXsxR8u8oTZea7h1H/ZXpkX6WC+fzqQZMormc0Fmb+2M1AWDMf7SRhMkSy6ZKtxVqR6scQE9dYZIexuKpgqAj2AX/TxvxBWq4Gc+sKM7NjfyQ90MohORaYodjb0k3JtuTK0fK8PMRogHKOEhHvfFvJZfUjcxGpenykcfmRQIDAQAB
08-27 10:01:39.442 17148 17148 E MainActivity: 1.公钥经base64编码 : 
08-27 10:01:39.442 17148 17148 E MainActivity: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAy4hV/WE8ubM4iWY5YhKAG29Uaq3WnQ5Ah77Nm+NQMQ9W6q4ROEhrEJ8NlV6/bs3JGaEEXjX0lfTd3IuHAPmZkUfWPefdOOWY/DrekzZFe3o4guwQYqz6ClxIVk/cvQWsEBYfdnpIqMYTa1bsaSHLZ9R0HM6kyb62spNZr0Wgmf86ppcGXsxR8u8oTZea7h1H/ZXpkX6WC+fzqQZMormc0Fmb+2M1AWDMf7SRhMkSy6ZKtxVqR6scQE9dYZIexuKpgqAj2AX/TxvxBWq4Gc+sKM7NjfyQ90MohORaYodjb0k3JtuTK0fK8PMRogHKOEhHvfFvJZfUjcxGpenykcfmRQIDAQAB
08-27 10:01:39.442 17148 17148 E MainActivity: 2.公钥base64解码后 :
08-27 10:01:39.443 17148 17148 I System.out: buff = 30820122300d06092a864886f70d01010105000382010f003082010a0282010100cb8855fd613cb9b3388966396212801b6f546aadd69d0e4087becd9be350310f56eaae1138486b109f0d955ebf6ecdc919a1045e35f495f4dddc8b8700f9999147d63de7dd38e598fc3ade9336457b7a3882ec1062acfa0a5c48564fdcbd05ac10161f767a48a8c6136b56ec6921cb67d4741ccea4c9beb6b29359af45a099ff3aa697065ecc51f2ef284d979aee1d47fd95e9917e960be7f3a9064ca2b99cd0599bfb63350160cc7fb49184c912cba64ab7156a47ab1c404f5d61921ec6e2a982a023d805ff4f1bf1056ab819cfac28cecd8dfc90f7432884e45a6287636f493726db932b47caf0f311a201ca384847bdf16f2597d48dcc46a5e9f291c7e6450203010001
08-27 10:01:39.445 17148 17148 E MainActivity: 3.最终公钥为: 
08-27 10:01:39.445 17148 17148 E MainActivity: OpenSSLRSAPublicKey{modulus=cb8855fd613cb9b3388966396212801b6f546aadd69d0e4087becd9be350310f56eaae1138486b109f0d955ebf6ecdc919a1045e35f495f4dddc8b8700f9999147d63de7dd38e598fc3ade9336457b7a3882ec1062acfa0a5c48564fdcbd05ac10161f767a48a8c6136b56ec6921cb67d4741ccea4c9beb6b29359af45a099ff3aa697065ecc51f2ef284d979aee1d47fd95e9917e960be7f3a9064ca2b99cd0599bfb63350160cc7fb49184c912cba64ab7156a47ab1c404f5d61921ec6e2a982a023d805ff4f1bf1056ab819cfac28cecd8dfc90f7432884e45a6287636f493726db932b47caf0f311a201ca384847bdf16f2597d48dcc46a5e9f291c7e645,publicExponent=10001}
08-27 10:01:39.446 17148 17148 E MainActivity: test1: source = 1234567890abcdef
08-27 10:01:39.446 17148 17148 E MainActivity: 1.原数据为:1234567890abcdef
08-27 10:01:39.455 17148 17148 E RSAUtil : encryptByPrivateKey: data.len = 16 outLen = 256
08-27 10:01:39.476 17148 17148 E MainActivity: 2.私钥加密,加密后数据为: 耗时 31 ms 
08-27 10:01:39.477 17148 17148 I System.out: buff = 6a30f71c9c8c4c1bc024afbcf7a78aee10858a7e79b3081a362e954cf732788158847f96e66375b5c556eda8145fb580332ca7026e8a2686a13adf9905ccfbfff8e5cef6b040f438e310e84a83306dd2489cf8c5de3a9e1a62c77af497f675ee783aeaaa9ad08f03273e50a4ff0dddf58198b29d7c48f259e926ed2f3f2ea1fd45acd50bc59a340aaf2ccdaf0da47962d39e7a7f1ef9202083b1c79bf779c95e05f9d6c6cc345ca923b21650afc11170d31129572588b1ae4f4092ea8e8ad25462007965013eda62e3609cd35b1e6c2a95e72f85eb206edd4a95f4801f991711b8090d095395d6d3fb4a3480a2c5759f04d6b77f7efba9580b8c3f4295ccb140
08-27 10:01:39.493 17148 17148 E MainActivity: 3.私钥签名,签名后数据为:
08-27 10:01:39.494 17148 17148 I System.out: buff = 37482d5d6b910ac1e4791c56178bed32b0973b8059574ea442abe04be8a3932ef68e120fba0165c3c4ee7847fd58ea9695e9aa8631cd304da967cf2d9ecb6ae01130d4cadf824f28a3aba745f6bfec308a0a1e2dc4cd98f56e5cec2af1a431504f72699c3db5feaa8f8d6a3aed87f5f5f1ba844dfa11811c43640ff840fba0c73ec974f92ef0819ed67249ded4968a45f928965bbe663effc6c91baddd32967e6b26ec97421c0d4e25c881962575cde72871115ac9c2302328a0096246f5b608c42a5c13b4648735b0431243086e9fb3863ad2d1d1e3651cf65611378058261485b0923b1e29c599c174029aae4360f8e44dc5a945a38e1f03fe11415f0b2102
08-27 10:01:39.494 17148 17148 E MainActivity: 
08-27 10:01:39.494 17148 17148 E MainActivity: 4.Base64编码(加密数据+签名):
08-27 10:01:39.494 17148 17148 E MainActivity: ajD3HJyMTBvAJK+896eK7hCFin55swgaNi6VTPcyeIFYhH+W5mN1tcVW7agUX7WAMyynAm6KJoah
08-27 10:01:39.494 17148 17148 E MainActivity: Ot+ZBcz7//jlzvawQPQ44xDoSoMwbdJInPjF3jqeGmLHevSX9nXueDrqqprQjwMnPlCk/w3d9YGY
08-27 10:01:39.494 17148 17148 E MainActivity: sp18SPJZ6SbtLz8uof1FrNULxZo0Cq8sza8NpHli0556fx75ICCDsceb93nJXgX51sbMNFypI7IW
08-27 10:01:39.494 17148 17148 E MainActivity: UK/BEXDTESlXJYixrk9AkuqOitJUYgB5ZQE+2mLjYJzTWx5sKpXnL4XrIG7dSpX0gB+ZFxG4CQ0J
08-27 10:01:39.494 17148 17148 E MainActivity: U5XW0/tKNICixXWfBNa3f377qVgLjD9ClcyxQDdILV1rkQrB5HkcVheL7TKwlzuAWVdOpEKr4Evo
08-27 10:01:39.494 17148 17148 E MainActivity: o5Mu9o4SD7oBZcPE7nhH/VjqlpXpqoYxzTBNqWfPLZ7LauARMNTK34JPKKOrp0X2v+wwigoeLcTN
08-27 10:01:39.494 17148 17148 E MainActivity: mPVuXOwq8aQxUE9yaZw9tf6qj41qOu2H9fXxuoRN+hGBHENkD/hA+6DHPsl0+S7wgZ7Wckne1JaK
08-27 10:01:39.494 17148 17148 E MainActivity: Rfkollu+Zj7/xskbrd0yln5rJuyXQhwNTiXIgZYldc3nKHERWsnCMCMooAliRvW2CMQqXBO0ZIc1
08-27 10:01:39.494 17148 17148 E MainActivity: sEMSQwhun7OGOtLR0eNlHPZWETeAWCYUhbCSOx4pxZnBdAKarkNg+ORNxalFo44fA/4RQV8LIQI=
08-27 10:01:39.495 17148 17148 E MainActivity: 
08-27 10:01:39.495 17148 17148 E MainActivity: 5.Base64解码:
08-27 10:01:39.495 17148 17148 I System.out: buff = 6a30f71c9c8c4c1bc024afbcf7a78aee10858a7e79b3081a362e954cf732788158847f96e66375b5c556eda8145fb580332ca7026e8a2686a13adf9905ccfbfff8e5cef6b040f438e310e84a83306dd2489cf8c5de3a9e1a62c77af497f675ee783aeaaa9ad08f03273e50a4ff0dddf58198b29d7c48f259e926ed2f3f2ea1fd45acd50bc59a340aaf2ccdaf0da47962d39e7a7f1ef9202083b1c79bf779c95e05f9d6c6cc345ca923b21650afc11170d31129572588b1ae4f4092ea8e8ad25462007965013eda62e3609cd35b1e6c2a95e72f85eb206edd4a95f4801f991711b8090d095395d6d3fb4a3480a2c5759f04d6b77f7efba9580b8c3f4295ccb14037482d5d6b910ac1e4791c56178bed32b0973b8059574ea442abe04be8a3932ef68e120fba0165c3c4ee7847fd58ea9695e9aa8631cd304da967cf2d9ecb6ae01130d4cadf824f28a3aba745f6bfec308a0a1e2dc4cd98f56e5cec2af1a431504f72699c3db5feaa8f8d6a3aed87f5f5f1ba844dfa11811c43640ff840fba0c73ec974f92ef0819ed67249ded4968a45f928965bbe663effc6c91baddd32967e6b26ec97421c0d4e25c881962575cde72871115ac9c2302328a0096246f5b608c42a5c13b4648735b0431243086e9fb3863ad2d1d1e3651cf65611378058261485b0923b1e29c599c174029aae4360f8e44dc5a945a38e1f03fe11415f0b2102
08-27 10:01:39.501 17148 17148 E RSAUtil : decryptByPublicKey: data.len = 256 outLen = 256
08-27 10:01:39.502 17148 17148 E RSAUtil : decryptByPublicKey: outLen = 0 inLen = 256
08-27 10:01:39.504 17148 17148 E MainActivity: 
08-27 10:01:39.504 17148 17148 E MainActivity: 6.公钥解密,解密后数据为:耗时 8 ms 
08-27 10:01:39.505 17148 17148 I System.out: buff = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000031323334353637383930616263646566
08-27 10:01:39.508 17148 17148 E RSAUtil : decryptByPublicKey: data.len = 256 outLen = 256
08-27 10:01:39.509 17148 17148 E RSAUtil : decryptByPublicKey: outLen = 0 inLen = 256
08-27 10:01:39.509 17148 17148 E MainActivity: 7.公钥解签,解签后数据为: 
08-27 10:01:39.510 17148 17148 I System.out: buff = 0001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff003031300d0609608648016503040201050004208e9916c5340c43fa003fe2dd54cd4e3027affbfc0d631e4cd858f64ec09fa9ed
08-27 10:01:39.511 17148 17148 E RSAUtil : verify: data: 
08-27 10:01:39.511 17148 17148 I System.out: buff = 31323334353637383930616263646566
08-27 10:01:39.511 17148 17148 E RSAUtil : verify: signed: 
08-27 10:01:39.512 17148 17148 I System.out: buff = 37482d5d6b910ac1e4791c56178bed32b0973b8059574ea442abe04be8a3932ef68e120fba0165c3c4ee7847fd58ea9695e9aa8631cd304da967cf2d9ecb6ae01130d4cadf824f28a3aba745f6bfec308a0a1e2dc4cd98f56e5cec2af1a431504f72699c3db5feaa8f8d6a3aed87f5f5f1ba844dfa11811c43640ff840fba0c73ec974f92ef0819ed67249ded4968a45f928965bbe663effc6c91baddd32967e6b26ec97421c0d4e25c881962575cde72871115ac9c2302328a0096246f5b608c42a5c13b4648735b0431243086e9fb3863ad2d1d1e3651cf65611378058261485b0923b1e29c599c174029aae4360f8e44dc5a945a38e1f03fe11415f0b2102
08-27 10:01:39.513 17148 17148 I System.out: engineVerify21
08-27 10:01:39.513 17148 17148 I System.out: engineVerify23
08-27 10:01:39.514 17148 17148 E MainActivity: 
08-27 10:01:39.514 17148 17148 E MainActivity: 8.公钥验证,结果为: true

此例子中:

用公钥解密出来的签名数据是

0001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

00 303130 0d 06096086 48 01 65 03040201 05 00 04 20

8e9916c5340c43fa003fe2dd54cd4e3027affbfc0d631e4cd858f64ec09fa9ed

原始数据是

31323334353637383930616263646566

而原始数据的sha256是

8E9916C5340C43FA003FE2DD54CD4E3027AFFBFC0D631E4CD858F64EC09FA9ED

 

你可能感兴趣的:(用梨子来理解rsa的验签过程)