RSA加密常用的填充方式有下面3种:
-----BEGIN RSA PRIVATE KEY----- MIICXAIBAAKBgQDJTwCsWHU4MTzHkZOiG2otXsG3kEHPh5C68M7CQf1f+DK/NRD/ pEj9kk98+hx2hQKlAIKHe3JFT6TXNONVeJGMX+8o1i5V7VSFiedmgbFAJdn3Ginv 0xQJuon0WUjymY66bD4c5xEXZWNTDmI2sPcZ0/3NgShBEGmCw6j+7EdQSwIDAQAB AoGAJIjYAG9VZstY0odTGdqL3IwT8DKYHwfldmf5vjuntmEfJKCG4z53mL2S+4WQ 4Nmm7zc2eUwoIvgfXIdWss5c66A3NBUPg1Q3XcWVTvx50pLtcTH9uVPWOYc5ZF68 kJdobmZgsfqrgkBpDSeWkDwih0H5P3SoVlX/6p16PACWy/ECQQD6r96HRIaJrcmS 6K+E5K5+ADgEfn4tiT7tAZ8MCAp84CYgJtCnGTlqc+MCx874UQ8x4SGff5qh0iyo fL8eOsTnAkEAzZM5r7wK+NZCHyJudUUe62QNs1StD5OLXRL+/WyoJRjdwspzkLw6 MD4M+wlBOOl3UN8gaVjc4QwnBp8GBKiI/QJAJ8EmH/ts/n5x3ftKgl+lkFPGjmfk 6KHAOeOs7kKEL0N4qFafdjBY25nfITzAhL6OE1HpfBrHUew7qsiFomyddwJAMZrj Apq3cxAQaH7gdH+3VEmSXMGD+Qw7Rrw8t14uvLThXg2IEVa6G8X9T94N1PPRDLyq j4EX214ZVKmuxBT+6QJBAPqAe2riAeNzYNmy4efed7bktAkZdvEu80mWsJ51BeX4 37xs3pWLoWwZomSgLd+ACl+AaJJS6CgTAyNUlWCbX+M= -----END RSA PRIVATE KEY-----
-----BEGIN RSA PUBLIC KEY----- MIGJAoGBAMlPAKxYdTgxPMeRk6Ibai1ewbeQQc+HkLrwzsJB/V/4Mr81EP+kSP2S T3z6HHaFAqUAgod7ckVPpNc041V4kYxf7yjWLlXtVIWJ52aBsUAl2fcaKe/TFAm6 ifRZSPKZjrpsPhznERdlY1MOYjaw9xnT/c2BKEEQaYLDqP7sR1BLAgMBAAE= -----END RSA PUBLIC KEY-----
待加密数据(HexString)
E4 B4 09 19 76 F1 2E F3 49 96 B0 9E 75 05 E5 F8 DF BC 6C DE 95 8B A1 6C 19 A2 64 A0 2D DF 80 0A 5F 80 68 92 52 E8 28 13 03 23 54 95 60 9B 5F E3
填充方式
RSA_PKCS1_PADDING
私钥加密结果(HexString)
2E 61 DB 7A DC C4 E8 68 11 46 5C DD 92 1F 4D 65 77 57 0E AD 1C 98 18 62 FB 36 80 68 FE A4 0D 72 B2 60 C7 84 B1 DC 40 C9 2C 14 58 F1 FA FC 9C 41 FF 1E BC EB E2 4D BA A3 2E BD 4A 09 9D BA 9B F2 10 69 A4 0B 68 76 DB 8E A3 49 D8 23 3C 3F 8E 45 5A 54 D0 E8 43 EB 21 67 E5 34 7C EE 7A B5 07 61 FA 71 9A 29 6F 6D BD 57 CF 89 AB E5 BB C1 33 FB 15 46 4E 61 44 A3 AB FA DA D6 AB 46 49 2C 7C B0
公钥加密结果
3E FC 34 B3 95 04 FD C6 44 89 DB 19 07 BC D3 B0 FB 95 B1 7B 2E 3E F7 C3 CB B0 0F 80 36 88 4D DA 30 6B 16 D8 6B 5C C1 58 17 CE 99 F3 CA 8B BA 8F F9 56 2D 16 83 97 BF A8 71 42 75 FC 80 58 32 7E 39 91 B2 77 DD 99 38 81 CC 26 2F 34 82 ED 05 81 53 30 A2 F5 E5 20 B0 9C A8 1D CC 93 FA 2A 97 40 6F FC 17 B9 6D F1 82 53 07 30 B7 35 5E D8 89 CA FF 56 5C 28 D1 A1 EF 08 33 B6 85 BF F5 B0 08 1Copenssl RSA encrypt 命令
--RSA_PKCS1_PADDING,在使用下面命令的时候,要求文件小于等于密钥长度-PKCS1_PADDING_SIZE(11)。 openssl rsautl -encrypt -inkey test.pem -in test.data -out test.pri.enc openssl rsautl -encrypt -inkey test.pub -pubin -in test.data -out test.pub.enc --RSA_NO_PADDING, 要求文件大小与密钥长度一样,此处为1024字节 openssl rsautl -encrypt -inkey test.pem -raw -in test.data -out test.pri.enc openssl rsautl -encrypt -inkey test.pub -pubin -raw -in test.data -out test.pub.enc --RSA_PKCS1_OAEP_PADDING,要求文件小于等于密钥长度-PKCS1_OAEP_PADDING_SIZE(42) openssl rsautl -encrypt -inkey test.pem -oaep -in test.86 -out test.pri.oaep.enc openssl rsautl -encrypt -inkey test.pub -pubin -oaep -in test.86 -out test.pub.oaep.enc --pkeyutl encrypt 命令 openssl pkeyutl -encrypt -in test.data -inkey test.pub -pubin -pkeyopt rsa_padding_mode:pkcs1 -out test.pub.enc