2013-02-26 33 views
0

我正在使用Kaffe JVM(等同於java 1.1)加密數據並嘗試使用JDK7解密數據。序列化BigInteger:符號幅度不匹配

在我的算法中,我使用BigInteger(RSA encription)。當我在JDK中測試應用程序時,所有的確定,但是當我嘗試從Kaffe JVM中生成的BigIntegers中的JDK7反序列化時,我得到下面列出的這個異常。

我在的問題很多原因想:

任何想法如何解決或檢測問題的原因?

在此先感謝。

java.io.StreamCorruptedException: BigInteger: signum-magnitude mismatch 
at java.math.BigInteger.readObject(BigInteger.java:3113) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:601) 
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1004) 
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1866) 
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771) 
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347) 
at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1685) 
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1341) 
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1964) 
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1888) 
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771) 
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347) 
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369) 
at commons.persistence.PersisterDataBigIntegerBuffer.fileToObjects(PersisterDataBigIntegerBuffer.java:87) 
at commons.persistence.CryptoRSAFileManager.getDataFromFile(CryptoRSAFileManager.java:44) 
at test.commons.csv.ParserTester.test(ParserTester.java:41) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:601) 
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) 
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) 
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) 
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) 
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) 
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) 
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) 
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) 
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) 
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) 
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) 
at org.junit.runners.ParentRunner.run(ParentRunner.java:309) 
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) 
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 

回答

1

它看起來像序列化格式的差異。

要解決此問題,您可能必須繼承BigInteger的子類並在從源JDK中找出存儲格式後重寫readObject方法。爲了給你一個提示,你在這裏提供了BigInteger的readObject的相關部分:

// Read the alternate persistent fields that we care about 
int sign = fields.get("signum", -2); 
byte[] magnitude = (byte[])fields.get("magnitude", null); 

// Validate signum 
if (sign < -1 || sign > 1) { 
    String message = "BigInteger: Invalid signum value"; 
    if (fields.defaulted("signum")) 
     message = "BigInteger: Signum not present in stream"; 
    throw new java.io.StreamCorruptedException(message); 
}