f



RSA cipher keeps giving error BadPaddingException: Message is larger than modulus

I'm trying to encrypt a byte array using a public key I get from a
network stream. The problem is that that the cipher keeps giving me an
error:

"BadPaddingException: Message is larger than modulus"

here is the code:

_rsaKey is a byte array (size 128)
temp is a zero filled byte array (size)
======================================================
kfac = KeyFactory.getInstance("RSA")
modulus = BigInteger(self._rsaKey)
kspec1 = RSAPublicKeySpec(modulus, RSAKeyGenParameterSpec.F4)
publicKey = kfac.generatePublic(kspec1)

rsaCipher = Cipher.getInstance("RSA/ECB/nopadding")
rsaCipher.init(Cipher.ENCRYPT_MODE, publicKey)
rsaEncryptedData = rsaCipher.doFinal(temp,0x00,0x80)
======================================================

everything goes well up until rsaCipher.doFinal(temp,0x00,0x80)
which throws the exception mentioned above

sometimes i get the exception, sometimes i don't. don't know whats
wrong.

example data values that threw that exception:

==============================================
_rsaKey: array('b',[-111, 56, 32, -77, 103, -86, -102, -89, 20, -74,
70, -116, 8
1, -107, -118, -67, -11, 120, 100, 17, -6, -21, -34, -1, 80, 46, -28,
-90, -42,
-2, -113, -61, -43, 30, 34, -35, -4, -8, 75, 98, -82, 23, -16, -19,
87, 56, -89,
 -89, 95, 57, -47, -70, 40, -126, -17, 106, -81, 62, 76, -79, 6, -37,
54, -64, -
3, 75, 79, -92, 115, -97, 96, 40, 16, -90, -31, 101, 102, 88, 78, -47,
21, -90,
50, -12, 112, -54, -78, -38, 17, -108, -60, 96, 123, 74, 87, -46, -44,
63, -19,
-62, 89, 48, -14, -35, 81, 76, 96, 82, 105, -112, -91, 30, -34, -3,
96, 96, 104,
 -97, 120, -86, 17, -127, -86, 120, 63, -23, -45, 67])

modulus:
-73073110056286640340097954246863433406112399401091916201456987043760182047884172
921300903878547695582385476703704119802885172774202508430737971758333982209240166
114559892444958685053471229837771943027402558952284852854396505019440462809471970
625231422840483143051964274679306161359974365557628502797717641392

temp:
array('b',[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0])
0
the.ech0 (11)
4/14/2009 6:47:48 AM
comp.lang.java.programmer 52714 articles. 0 followers. Post Follow

1 Replies
2558 Views

Similar Articles

[PageSpeed] 41

According to ech0  <the.ech0@gmail.com>:
> _rsaKey is a byte array (size 128)
> temp is a zero filled byte array (size)
> ======================================================
> kfac = KeyFactory.getInstance("RSA")
> modulus = BigInteger(self._rsaKey)
> kspec1 = RSAPublicKeySpec(modulus, RSAKeyGenParameterSpec.F4)
> publicKey = kfac.generatePublic(kspec1)
> 
> rsaCipher = Cipher.getInstance("RSA/ECB/nopadding")
> rsaCipher.init(Cipher.ENCRYPT_MODE, publicKey)
> rsaEncryptedData = rsaCipher.doFinal(temp,0x00,0x80)
> ======================================================

This is not Java code; for instance, it lacks a "new" just before
"BigInteger". That being said, there are a number of problems in what
you try to do:

-- The BigInteger(byte[]) constructor expects a binary representation
of an integer, in big-endian _signed_ notation. I.e., if the high bit
of the first byte is set, you will end up with a negative modulus, which
is not good for RSA. Use BigInteger(int, byte[]) instead.

-- "ECB" and "nopadding" make little sense for RSA. These are parameters
for symmetric encryption algorithm.

-- RSA, as an encryption algorithm, is defined by PKCS#1, which
specifies several kind of transformations which are applied to the input
data before computing the modular exponentiation which lies at the core
of RSA. Those transformations are called "padding" in PKCS#1 but they
are not to be confused with any "padding" from the realm of symmetric
ciphers. More precisely, two paddings are defined for RSA: the new
padding named "OAEP", and the old padding called "v1.5". The old padding
is the one which accepts the largest input message (with regards to the
modulus) and is also the one which is used just about everywhere.
Nevertheless, both paddings add some bytes to the data. With v1.5, the
maximum size of the input message is 11 bytes less than the modulus.
Thus, if the modulus is an integer greater than 2^1016 and less than
2^1024 (i.e. the kind of modulus which you will encode as 128 bytes),
then the maximum message size which you will encrypt with it is 117
bytes. No more.


You may have other bugs as well.


	--Thomas Pornin
0
pornin1 (320)
4/14/2009 12:27:21 PM
Reply:

Similar Artilces:

[compilation error] debugging this error message "Object() in java.lang.Object cannot be applied to"
Hi,I have a class called Device that instantiates another class DbMoneyin this manner:=== return new DbMoney( money, hardware.getName() );===1) Both are in the same package, i.e. my.IMoney & my.Device2) When I compile them, javac complains with the error:Object() in java.lang.Object cannot be applied to (my.IMoney,java.lang.String) return new DbMoney( money, hardware.getName() ) ^Q) My arguments to the DbMoney constructor match that of its declaredmethod parameters. So that can't be the problem. What am I doingwrong ?Gavin On Mar 28, 3:25 pm, "Gavin&...

Error occurred during intialization of VM java/lang/NoClassDefFoundError: java/lang/Object
Good day to all, I have installed the j2se/netbeans binary bundle on red hat 9. I can run everything perfectly as root but when I try to compile with any other user I get: Error occurred during intialization of VM java/lang/NoClassDefFoundError: java/lang/Object When I saw this it seemed like a permissions problem but I checked the permissions and everything seemed fine. All users have execute permissions of javac and java. I have read other threads dealing with the same or similar problem but have not reached any solution yet. I would appreciate if anyone that has run into this type o...

Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object
I downloaded jdk-6u7-solaris-sparcv9.tar.Z and installed it by these commands: # zcat jdk-6u7-solaris-sparc.tar.Z | tar -xf - # pkgadd -d . SUNWj6rtx SUNWj6dvx SUNWj6dmx # /usr/jdk/instances/jdk1.6.0/bin/sparcv9/java -version Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object # ls /usr/jdk/instances/ jdk1.5.0 jdk1.6.0 # uname -a SunOS sun1 5.10 Generic sun4u sparc SUNW,Sun-Blade-2500 Please help to fix the error. Thanks. TsanChung wrote: > I downloaded jdk-6u7-solaris-sparcv9.tar.Z and installed it by these > commands: > # zcat jdk-6u7-so...

Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object (ant/tomcat/spring)
Hi, I've been trying to get Spring working with ant and tomcat. Ant was building just fine, but I came in today and tried to build it and got this: Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object ?!?! Makes no sense to me. There _is_ an older version of java installed on my machine; but JAVA_HOME and ANT_HOME are set to the correct paths, and <which java>and <java -version> produce the correct version. Any help would greatly alleviate my frustration! Thanks in advance... Courtney ...

Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object (ant/tomcat/spring)
Hi, I've been trying to get Spring working with ant and tomcat. Ant was building just fine, but I came in today and tried to build it and got this: Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object ?!?! Makes no sense to me. There _is_ an older version of java installed on my machine; but JAVA_HOME and ANT_HOME are set to the correct paths, and <which java>and <java -version> produce the correct version. Any help would greatly alleviate my frustration! Thanks in advance... Courtney ...

java.lang.IllegalAccessError: tried to access method Error Message
Looking for help to troubleshoot an java.lang.IllegalAccessError message. I am getting this error message at run time. While searching for this error message I have found that this could be a problem with different versions of the same jar. How do I find out which jar is causing the problem? I will also include my maven pom.xml and services.xml. Thanks in advance for your help. 2008-10-21 14:40:59,630 WARN [http-8080-Processor23] RemoteInvocationTraceInterceptor - Processing of HttpInvokerServiceExporter remote call resulted in fatal exception: com.saic.pf.lib.security.PfLoginManager.log...

Validator gives: "Uncaught error java.lang.Exception: Import loop detected"
Hi, When I validate this page: http://www.drfunkenstein.net/using http://jigsaw.w3.org/css-validator/, I get the following results: http://jigsaw.w3.org/css-validator/validator?profile=css2&warning=2&uri=http%3A//www.drfunkenstein.net/ Or briefly: "Uncaught error java.lang.Exception: Import loop detected in http://www.drfunkenstein.net/styles/base.css" I'm guessing that the validator is telling me there's some kind of loop created by the import statements in my CSS, but I can't for the life of me see the error. The java.lang.Exception part makes...

java error message java.io not found in import
Hi i'm trying to run a code like but i'm getting all the time the same error Class java.io not found in import import Java.io i guess the problem is that i dont have the header in the include folder,doenst anyone have solution for me? thread wrote: > Hi i'm trying to run a code like but i'm getting all the time the same > error > Class java.io not found in import > import Java.io 1. Capitalization matters. The package name is `java.io', not `Java.io' 2. The first-person subjective pronoun is `I', not `i'. 3. There is no class `java.io'; there ...

Error Code :17410 Error State :null Error Message :No more data to read from socket Stack Trace : java.sql.SQLException: No more data to read from socket
Hi, I see the following errors in the logs: Error Code :17410 Error State :null Error Message :No more data to read from socket Stack Trace : java.sql.SQLException: No more data to read from socket at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:114) at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:156) at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:803) at oracle.jdbc.ttc7.MAREngine.unmarshalUB1(MAREngine.java:731) at oracle.jdbc.ttc7.MAREngine.unmarshalSB1(MAREngine.java:690) at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:372) at oracle.jdbc.ttc7...

compile errors for Game The main program is giving me errors projectJS.java
Hello again. I've only included two of the 13 programs for this game. The main program projectJS.java is giving me compile errors and the other program containing private BoardPanel boardPanel; private WinningsPanel winningsPanel; public GameFrame(String name, BoardPanel boardPanel, WinningsPanel winningsPanel) is connected to it somehow but i don't understand how to fix the errors here are the two programs and here are the compile errors. //GameFrame.java package chapter14; import java.awt.*; import java.awt.event.*; import javax.swing.*; import static chapter14.projectJS.*; class ...

java.lang errors
I have a program that takes in data from the user, calculates the data and is supposed to display the results in a window. The program compiles and the user is able to type in data, but when you click the calculate button, the errors that come up are the following: java.lang.NumberFormatException: For input string: "Enter Length" at java.lang.NumberFormatException.forInputString (NumberFormatException. java:48) at java.lang.Integer.parseInt(Integer.java:468) at java.lang.Integer.parseInt(Integer.java:518) at Program81$ButtonHandler.actionPerformed(Pro...

java error message?
Recently I've been getting the following message when I visit different sites: "Internet Explorer can not open this helper application for dtdp://748/331/1/jgen44.cjt1.net/HTM/704/0/javasiterequest.asp?LV=60008DC=453&NFD&IW=7208JH=300&ORD=1111355390281?&. The protocol specified in this address is not valid. Make sure the address is correct and try again." I think I copied it correctly (kinda blurry, had to copy as bitmap). Any idea what is missing here? What "request" is being made from this site, or what helper application is missing? Was i...

Java Error Message
I have checked my config.sys file and have no mention of Java 1.1.6 installed. Everything points to Java 1.4. When I attempt to run LVMGUI I get the following error message: [C:\]lvmgui You are running Java Version 1.1.6 [C:\OS2\JAVAAPPS]JAVAPM -nojit lvmgui SYS1041: The name JAVAPM is not recognized as an internal or external command, operable program or batch fil 63 *-* javapm '-nojit' progname parameters; +++ RC(1041) How do I resolve this? What have I done wrong? Thanks, Hap-- Sir: A. Willard Reese wrote: > I have checked my...

java.lang.ExceptionInInitializerError: java.lang.ArrayIndexOutOfBoundsException
Hi, I am new to DB2. I am getting this error while loading the DB2Driver. I don't have any idea about where i might have gone wrong. please help me. Below is the stack trace. Stack Trace: java.lang.ExceptionInInitializerError: java.lang.ArrayIndexOutOfBoundsException at COM.ibm.db2.jdbc.app.DB2Driver.SQLAllocEnv(Native Method) at COM.ibm.db2.jdbc.app.DB2Driver.<init>(DB2Driver.java:245) at COM.ibm.db2.jdbc.app.DB2Driver.<clinit>(DB2Driver.java:130) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Cla...

XML-RPC
Hello, I am getting an error "XML-RPC - java.lang.ClassCastException: java.util.Date" when I call the "XmlRpcClient" execute method. I believe the underlying classes are having trouble parsing the result from the time.xmlrpc.com/RPC2:80 XML-RPC service. I apologize that I could not navigate the Apache bug reporting and search system. I hope someone can recognize what is up with this. Thank you in advance for any help, Michael import java.util.Vector; import java.util.Hashtable; import org.apache.xmlrpc.*; public class GetTime { private final static String serv...

JAVA error message
I am trying to get a handle on the experimental ODS graphics output for proc corr and encountered a problem. ods graphics on; ods html file='C:\MOMA_Analysis\correl.html'; proc corr data=MOMA.meansincolumns nosimple plots=MATRIX; var angle heading seed_yld Seed_mass Til_N Til_dia Til_Len S_Nod Pan_len Pan_nod L_len L_wid; run; ods html close; ods graphics off; run; The following error message was displayed: 'The unsupported JRE version 1.5 was installed.' Can't load class com/sas/tk/util/SetStandardOut. Can't redirect System.err to SAS log. Can't load clas...

chkdsk c: /f gives "An unspecified error occurred" error message
This is probably an XP issue, but can anyone help me getting "An unspecified error occurred"? After running 'chkdsk c: /f' from the command prompt, I get the prompt to run at startup which I say yes to. After startup, I get the 10 second countdown, and then immediately the message: "An unspecified error occurred." and then chkdsk terminates and xp pr sp2 loads. Is there any way to find out WHAT the error is? It happens on both c: and d: (paging file) drive. I can run chkdsk c: /p from the recovery console to do full scan for bad sectors, and bot...

java matlab error: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
Hello Im using matlab 2010 and 2007 with windows 7 and i have install the new java. Matlab array editor doesnt work right even though i can see the values of an array in the workspace when i try to edit them in the variable editor i cant see the values and i get an error: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at com.mathworks.mlwidgets.array.ValueTableModel.setValuesAt(ValueTableModel.java:195) at com.mathworks.mlwidgets.array.ValueTableModel.setValueAt(ValueTableModel.java:190) at com.mathworks.widgets.spreadsheet.ResizingTableModelWrapper.s...

java.lang.StringIndexOutOfBoundsException: String index out of range: 23 at java.lang.String.charAt(String.java:460)
Hi All I am having the torque3.1.jar and postgresql-7.4. I have compiled the new jdbc driver called as postgresql.jar and have placed it in the lib directory from where the ant scripts catch the jars. Whenever i try to access through torque gestList = BaseGestlistPeer.doSelect(new Criteria()); this error arises java.lang.StringIndexOutOfBoundsException: String index out of range: 23 at java.lang.String.charAt(String.java:460) at org.postgresql.jdbc2.ResultSet.toTimestamp(ResultSet.java:1653) at org.postgresql.jdbc2.ResultSet.getTimestamp(ResultSet.java...

The giving that keeps on giving
This is a money making program that will make you a some money in a relativel short time span. http://123Angelcash.googlepages.com How long it takes is up to you. I won't cost you much. No more than the cost of lunch at Burger King. Try it! You won't regret it! ...

(assert-error) tests errors and error messages
I wrote (assert-error) to make sure that a function generates an error, and verify the error message. What do you think? Below is the definition and a few test cases, for Emacs 22.1.50. (require 'cl) (defmacro assert-error (form &optional regexp) "FORM must signal an error. Signal an error otherwise. Additionally, the error message must match REGEXP. Case is ignored while matching REGEXP." (let ((msg (make-symbol "msg")) (ok (make-symbol "ok")) (res (make-symbol "res"))) `(let ((,ok nil)) (condition-case err ...

Java out of memory error message
Within the last couple of weeks I have started to get the following error message after running for a while: 'Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space' If I keep operating, the ML will crash. I am running 7.2.0.232 under Windows Vista Enterprise, with SP 2, 2.00 GB RAM. The software is installed on my PC, but our environment requires us to save data, etc. to a network drive. Any ideas? Barry "Barry Williams" <barry.r.williamsnospam@saic.com> wrote in message <jobqup$4pf$1@newscl01ah.mathworks.com>......

java.lang.UnsupportedClass error
> java -jar squirrel-sql-2.4-install.jar> Exception in thread "main" java.lang.UnsupportedClassVersionError: com/> izforge/i> zpack/installer/Installer (Unsupported major.minor version 48.0)> at java.lang.ClassLoader.defineClass0(Native Method)> at java.lang.ClassLoader.defineClass(Unknown Source)> at java.security.SecureClassLoader.defineClass(Unknown Source)> at java.net.URLClassLoader.defineClass(Unknown Source)> at java.net.URLClassLoader.access$100(Unknown Source)> at java.net.URLClassLoader$1.run(Unknown So...

Java compilation error message.
Attempting to write my first java program that accepts user input. When I add the listner events to the code it will not compile. Below is the code along with the error message: Code: import javax.swing.*; import java.awt.event.*; public class LottoEvent implements ItemListener, ActionListener, Runnable { } Compilation Error message: javac LottoEvent.Java: LottoEvent is not abstract and does not override abstract method itemStateChanged(java.awt.event.ItemEvent) in java.awt.event.ItemListener public class LottoEvent implements ItemListener, ActionListener, Runnable ...

Web resources about - RSA cipher keeps giving error BadPaddingException: Message is larger than modulus - comp.lang.java.programmer

Resources last updated: 2/25/2016 6:30:02 AM