On Feb 9, 4:33 am, Jeffrey Walton <[email protected]> wrote: > On Feb 8, 5:42 am, Leo Mifare <[email protected]> wrote: > > > > > Hi friends.. > > > i'm really confused how to encrypt data using PrivateKey , NO Padding, and > > Decrypt it using PublicKey. > > Hmm, actually i can solve this problem easily using Java.. > > But i want implement the process in my C++ application.. > > > *Snippet Code :* > > byte[] inputEncryption = > > ByteUtils.StringToHex("@ABCDEFGHIJKLMNO@ABCDEFGHIJKLMNO > > @ABCDEFGHIJKLMNO@ABCDEFGHIJKLMNO"); > > > //404142434445464748494A4B4C4D4E4F404142434445464748494A4B4C4D4E4F404142434445464748494A4B4C4D4E4F404142434445464748494A4B4C4D4E4F > > > Cipher rsaCipher2 = Cipher.getInstance("RSA/None/NoPadding"); > > RSAPublicKey myPubKEY = (RSAPublicKey) > > KeyFactory.getInstance("RSA").generatePublic(rsaPublicKeySpec); > > RSAPrivateKey myPrivKEY = (RSAPrivateKey) > > KeyFactory.getInstance("RSA").generatePrivate(rsaPrivateKeySpec); > > rsaCipher2.init(Cipher.ENCRYPT_MODE, myPrivKEY); > > byte[] output = rsaCipher2.doFinal(inputEncryption); > > System.out.println("OUTPUT Encryption = " + > > ByteUtils.HexToString(output)); > > > rsaCipher2.init(Cipher.DECRYPT_MODE, myPubKEY); > > output = rsaCipher2.doFinal(output); > > System.out.println("OUTPUT = " + ByteUtils.HexToString(output)); > > > *Snippet Console Output :* > > RSA Private Key Modulus = > > 00A9C985E853C94ADDA1969486896B657257580E695C7C92AC891DCB4041C8552F6F30CC9B7CA97C1213E31C8C8985EFB475B5572B73BE4446077AC31E614DFA67 > > RSA Private Key Exponent = > > 00806DDC69997F28AF2EFC7D0AAB45DE6DB81DF680C221C4BCD7D6FE987369FAEC73CB964D6E3F5C87BE3DBE8FE034FC96D13940E51EC4D82B791E84B334C951B9 > > Encrypted Data = > > 903B72E6DA4BEB674670A7723E17CFE6D6CC0939BD4CD43166B49A10194B3AC08F3433C1CF2484CC25C233AEA9A958DBF128AA19D8555BD87BA618E497B414B9 > > Decrypted Data = > > 404142434445464748494A4B4C4D4E4F404142434445464748494A4B4C4D4E4F404142434445464748494A4B4C4D4E4F404142434445464748494A4B4C4D4E4F > > > How to achieve that using Cryptopp > > > Please help me regarding this.. > > > Sorry i'm pretty new in this field.. > > The other folks are pretty much spot on regarding the 'encrypt with > private key'. The public exponent (e) is generally 3, 17, or 65537. > The private exponent (d) has a relationship to the public exponent > (ie, the trap door). The relationship is e*d === 1 mod (PHI(n)). > Anyway, you could swap 'e' and 'd' and things would still work. You > could also select any {e,d} pair that satisifies the congruence. But > its not recommended. > > Since you have you modulus, pub and prv exponent, package them into a > key manually. You will be interested in the 'Initialize' function of > RSA::PublicKey and RSA::PrivateKey. Seehttp://www.cryptopp.com/wiki/Rsa. Actually, this is the page for loading the keys: http://www.cryptopp.com/wiki/RSA_Signature_Schemes. See 'RSA Signature Generation Given d and n' and 'RSA Signature Verification Given e and n'. After loading the keys, encrypt/decrypt rather than sign/verify.
Jeff -- You received this message because you are subscribed to the "Crypto++ Users" Google Group. To unsubscribe, send an email to [email protected]. More information about Crypto++ and this group is available at http://www.cryptopp.com.
