使用DES(解密)的CBC

时间:2019-03-19 09:35:20

标签: android bouncycastle

美好的一天。出现问题,我无法理解它的含义。我有一个加密的字符串,其中前4个字节为大小。如何正确破译这条线? 解密行:

  

0x00、0x00、0x00、0x28、0x70、0x76、0x65,   0x25,(字节)0xe0,0x2c,0x6e,0x5f,0x36,0x69,0x7,(字节)0xb8,(字节)0xde,0x30,0x6d,0x56,(字节)0xa3,0x53,0x6d,(字节)0x8d,0x1c ,0x7e,(byte)0xed

这是我的代码:

byte[] keyBytes = new byte[]{0x00, 0x00, 0x00, 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,


                (byte) 0x00};

        byte[] SourceByte = new byte[]{0x70, 0x76, 0x65, 0x25,(byte)0xe0,0x2c,0x6e,0x5f,0x36,0x69,0x7,(byte)0xb8,(byte)0xde,0x30,0x6d,0x56,(byte)0xa3,0x53,0x6d,(byte)0x8d,0x1c,0x7e,(byte)0xed};



        byte[] ivBytes = new byte[]{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};


        SecretKeySpec pKey = new SecretKeySpec(keyBytes, "DES");

        IvParameterSpec ivectorSpecv = new IvParameterSpec(ivBytes);

        Cipher c = Cipher.getInstance("DES/CBC/PKCS7Padding", "BC");

解密:

int len = 40;
c.init(Cipher.DECRYPT_MODE, pKey, ivectorSpecv);
byte[] plainText = new byte[c.getOutputSize(len)];
int ptLength = c.update(SourceByte, 0, len, plainText, 0);
ptLength += c.doFinal(plainText, ptLength);
System.out.println("plain : " + new String(plainText) + " bytes: " + ptLength);

错误:

  

致命异常:主要                                                                                      流程:com.example.jone1.navigation_drawer,PID:7240                                                                                      java.lang.RuntimeException:无法启动活动   ComponentInfo {com.example.jone1.navigation_drawer / com.example.omen.serverforcofe.MainActivity}:   java.lang.IllegalArgumentException:错误的参数                                                                                          在   android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)                                                                                          在   android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)                                                                                          在android.app.ActivityThread.-wrap12(ActivityThread.java)                                                                                          在   android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1477)                                                                                          在android.os.Handler.dispatchMessage(Handler.java:102)                                                                                          在android.os.Looper.loop(Looper.java:154)                                                                                          在android.app.ActivityThread.main(ActivityThread.java:6119)                                                                                          在java.lang.reflect.Method.invoke(本机方法)                                                                                          在   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:886)                                                                                          在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)                                                                                       引起原因:java.lang.IllegalArgumentException:错误的参数                                                                                          在javax.crypto.Cipher.update(Cipher.java:1829)                                                                                          在   com.example.omen.serverforcofe.MainActivity.onCreate(MainActivity.java:128)                                                                                          在android.app.Activity.performCreate(Activity.java:6679)                                                                                          在   android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)                                                                                          在   android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)                                                                                          在   android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)                                                                                          在android.app.ActivityThread.-wrap12(ActivityThread.java)                                                                                          在   android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1477)                                                                                          在android.os.Handler.dispatchMessage(Handler.java:102)                                                                                          在android.os.Looper.loop(Looper.java:154)                                                                                          在android.app.ActivityThread.main(ActivityThread.java:6119)                                                                                          在java.lang.reflect.Method.invoke(本机方法)                                                                                          在   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:886)                                                                                          在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)03-19   09:24:41.970 1613-2258 / system_process W / ActivityManager:强制   整理活动   com.example.jone1.navigation_drawer / com.example.omen.serverforcofe.MainActivity   03-19 09:24:42.181 2316-2327 / com.google.android.gms I / art:背景   粘性并发标记清除GC已释放12310(933KB)AllocSpace对象,   9个(180KB)LOS对象,23%空闲,6MB / 9MB,总共暂停9.592ms   194.520ms 03-19 09:24:42.220 1295-1346 /? D / gralloc_ranchu:gralloc_alloc:格式1和用法0x900表示创建主机颜色   缓冲区03-19 09:24:42.232 1613-3805 / system_process I / OpenGLRenderer:   初始化的EGL版本1.4 03-19 09:24:42.233   1613-3805 / system_process D / OpenGLRenderer:交换行为1 03-19   09:24:42.234 1613-3805 / system_process W / OpenGLRenderer:失败   选择带有EGL_SWAP_BEHAVIOR_PRESERVED的配置,然后重试而无需...

0 个答案:

没有答案