BadPadding error trying to decrypt an encrypted text using RSA in java?

Up vote 0 down vote favorite share g+ share fb share tw.

Import java.awt. *; import javax.swing. *; import java.awt.event.

*; import java.net. *; import java.security. *; import javax.crypto.

*; import java.security.spec. RSAPublicKeySpec; import java.security.spec. RSAPrivateKeySpec; import java.math.

BigInteger; import java.io. *; public class te{ public static void main(String args)throws Exception, BadPaddingException{ String prm = "1356693815384374985786020038142368634468655364942303064968629976904326939996714307669149658585909884520869647876340752574207535591716198658155529888025635790189083217466451153081 269919397200690699534525643987865276277993880075999772490312417976020492378150309 39177321376213502000617956501365619136743391604527"; String pre = "19206980310240345089054650269266997266428253566713308882216247410797790472602897743665582297792448347068816600 544883817624645048626980493340327310227206380607181387937540249987606431866075725752492606382634185279280943886 308449677927309099658421773139598468152381904230858223190603151408714561182985778736217"; String pu = "13566938153843749857860200381423686344686553649423030649686299769043269399967143076691496585859098845208696478 763407525742075355917161986581555298880256357901890832174664511530812699193972006906995345256439878652762779938 8007599977249031241797602049237815030939177321376213502000617956501365619136743391604527"; String pue = "65537"; BigInteger m = new BigInteger(prm); BigInteger e = new BigInteger(pre); RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec(m,e); KeyFactory fact = KeyFactory. GetInstance("RSA"); PrivateKey priKey = fact.

GeneratePrivate(keySpec); BigInteger m1 = new BigInteger(pu); BigInteger e1 = new BigInteger(pue); RSAPublicKeySpec keySpec2 = new RSAPublicKeySpec(m1, e1); KeyFactory fact2 = KeyFactory. GetInstance("RSA"); PublicKey pubKey = fact2. GeneratePublic(keySpec2); Cipher cipher = Cipher.

GetInstance("RSA/ECB/PKCS1Padding"); cipher. Init(Cipher. ENCRYPT_MODE, pubKey); String st = "Hello"; byte cleartext = st.getBytes(); byte ciphertext = null; ciphertext = cipher.

DoFinal(cleartext); Cipher cipher2 = Cipher. GetInstance("RSA/ECB/PKCS1Padding"); cipher2. Init(Cipher.

DECRYPT_MODE, priKey); byte cleartext2 = cipher2. DoFinal(cleartext); System.out. Println("the encrypted text is " + ciphertext.toString()); System.out.

Println("the decrypted text is " + cleartext2.toString()); } } ======================================== please help! I have spent hours trying to decrypt the string, but I keep getting the following error. Exception in thread "main" javax.crypto.

BadPaddingException: Data must start with zero at sun.security.rsa.RSAPadding. UnpadV15(Unknown Source) at sun.security.rsa.RSAPadding. Unpad(Unknown Source) at com.sun.crypto.provider.RSACipher.

A(DashoA13*..) at com.sun.crypto.provider.RSACipher. EngineDoFinal(DashoA13*..) at javax.crypto.Cipher. DoFinal(DashoA13*..) at te.

Main(te. Java:57) runtime-error link|improve this question asked Aug 18 '11 at 14:02Chris11.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions


Thank You!
send