我正在尝试加密图库中的图像并将其存储在SD卡上。
当我试图将图像从图库移动到SD卡时,我收到“强制关闭”错误,而logcat没有显示异常。
我正在举杯说“图像已成功加密”,但它没有将图像从图库移动到SD卡。
我做错了什么?
private void encript(byte[] data, byte[] clear) {
byte[] keyBytes = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 };
SecretKeySpec key = new SecretKeySpec(keyBytes, "AES");
Cipher cipher = null;
try {
cipher = Cipher.getInstance("AES/ECB/PKCS7Padding", "BC");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchProviderException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
}
try {
cipher.init(Cipher.ENCRYPT_MODE, key);
} catch (InvalidKeyException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
byte[] cipherText = new byte[cipher.getOutputSize(data.length)];
// int ctLength = cipher.update(data, 0, data.length, cipherText, 0);
byte[] input = null;
try {
input = cipher.doFinal(cipherText);
} catch (IllegalBlockSizeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BadPaddingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try{
if(input.length>0){
Toast.makeText(getApplicationContext(), "Image successfully encripted", 3000).show();
}
ByteArrayInputStream bis = new ByteArrayInputStream(input);
ObjectInputStream ois = new ObjectInputStream(bis);
File encriptedfile = (File) ois.readObject();//This is the file which i want to Move to App folder
bis.close();
ois.close();
} catch (StreamCorruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return;
}
//Code for copy image into app folder......
File outputFolder = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + ".map");
try {
FileUtils.copyFile (encriptedfile, outputFolder);
}
catch (IOException e) {
Log.e("photomover", e.toString());
}
}
08-17 11:42:00.905: WARN/System.err(8453): java.io.StreamCorruptedException
08-17 11:42:00.905: WARN/System.err(8453): at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:2392)
08-17 11:42:00.905: WARN/System.err(8453): at java.io.ObjectInputStream.<init>(ObjectInputStream.java:445)
08-17 11:42:00.905: WARN/System.err(8453): at com.cw.GalleryShareimage1Activity.encript(GalleryShareimage1Activity.java:177)
08-17 11:42:00.905: WARN/System.err(8453): at com.cw.GalleryShareimage1Activity.onCreate(GalleryShareimage1Activity.java:76)
08-17 11:42:00.915: WARN/System.err(8453): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-17 11:42:00.915: WARN/System.err(8453): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2633)
08-17 11:42:00.915: WARN/System.err(8453): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2685)
08-17 11:42:00.915: WARN/System.err(8453): at android.app.ActivityThread.access$2300(ActivityThread.java:126)
08-17 11:42:00.915: WARN/System.err(8453): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2038)
08-17 11:42:00.915: WARN/System.err(8453): at android.os.Handler.dispatchMessage(Handler.java:99)
08-17 11:42:00.915: WARN/System.err(8453): at android.os.Looper.loop(Looper.java:123)
08-17 11:42:00.915: WARN/System.err(8453): at android.app.ActivityThread.main(ActivityThread.java:4633)
08-17 11:42:00.915: WARN/System.err(8453): at java.lang.reflect.Method.invokeNative(Native Method)
08-17 11:42:00.915: WARN/System.err(8453): at java.lang.reflect.Method.invoke(Method.java:521)
08-17 11:42:00.915: WARN/System.err(8453): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
08-17 11:42:00.915: WARN/System.err(8453): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
08-17 11:42:00.915: WARN/System.err(8453): at dalvik.system.NativeStart.main(Native Method)
08-17 11:42:00.925: WARN/dalvikvm(8453): threadid=1: thread exiting with uncaught exception (group=0x400207d8)
08-17 11:42:00.935: ERROR/AndroidRuntime(8453): FATAL EXCEPTION: main
08-17 11:42:00.935: ERROR/AndroidRuntime(8453): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cw/com.cw.GalleryShareimage1Activity}: java.lang.NullPointerException: Source must not be null
08-17 11:42:00.935: ERROR/AndroidRuntime(8453): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)
08-17 11:42:00.935: ERROR/AndroidRuntime(8453): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2685)
08-17 11:42:00.935: ERROR/AndroidRuntime(8453): at android.app.ActivityThread.access$2300(ActivityThread.java:126)
08-17 11:42:00.935: ERROR/AndroidRuntime(8453): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2038)
08-17 11:42:00.935: ERROR/AndroidRuntime(8453): at android.os.Handler.dispatchMessage(Handler.java:99)
08-17 11:42:00.935: ERROR/AndroidRuntime(8453): at android.os.Looper.loop(Looper.java:123)
08-17 11:42:00.935: ERROR/AndroidRuntime(8453): at android.app.ActivityThread.main(ActivityThread.java:4633)
08-17 11:42:00.935: ERROR/AndroidRuntime(8453): at java.lang.reflect.Method.invokeNative(Native Method)
08-17 11:42:00.935: ERROR/AndroidRuntime(8453): at java.lang.reflect.Method.invoke(Method.java:521)
08-17 11:42:00.935: ERROR/AndroidRuntime(8453): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
08-17 11:42:00.935: ERROR/AndroidRuntime(8453): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
08-17 11:42:00.935: ERROR/AndroidRuntime(8453): at dalvik.system.NativeStart.main(Native Method)
08-17 11:42:00.935: ERROR/AndroidRuntime(8453): Caused by: java.lang.NullPointerException: Source must not be null
08-17 11:42:00.935: ERROR/AndroidRuntime(8453): at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:1068)
08-17 11:42:00.935: ERROR/AndroidRuntime(8453): at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:1038)
08-17 11:42:00.935: ERROR/AndroidRuntime(8453): at com.cw.GalleryShareimage1Activity.onCreate(GalleryShareimage1Activity.java:96)
08-17 11:42:00.935: ERROR/AndroidRuntime(8453): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-17 11:42:00.935: ERROR/AndroidRuntime(8453): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2633)
08-17 11:42:00.935: ERROR/AndroidRuntime(8453): ... 11 more