首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

简略的加密部分资源

2012-09-29 
简单的加密部分资源这个呢 不是我弄的只是看到的,只是用作者的话说 如果别人真想知道怎么加密都是虚的只是

简单的加密部分资源

这个呢 不是我弄的只是看到的,只是用作者的话说 如果别人真想知道怎么加密都是虚的

只是为了不让简单的从sd卡内直接看到而已

?

原理就是自己写一个流通过与或 简单转一下而已

File assets = new File(Environment.getExternalStorageDirectory(),"assets");?
ZipInputStream zip = new ZipInputStream(new TranslateInputStream(assets));?

?

然后就是关键的

private static final byte MAGIC_NUMBER = 13;?
?
private void translateBuffer(byte[] buffer) {?
? ? for (int i = 0;i < buffer.length;i++) {?
? ? ? ? buffer[i] ^= MAGIC_NUMBER;?
? ? }?
}?
?
private class TranslateOutputStream extends FileOutputStream {?
? ? public TranslateOutputStream(File file) throws FileNotFoundException {?
? ? ? ? super(file);?
? ? }?
?
? ? @Override?
? ? public void write(int oneByte) throws IOException {?
? ? ? ? oneByte ^= MAGIC_NUMBER;?
? ? ? ? super.write(oneByte);?
? ? }?
?
? ? //In Android write(byte[]) calls this method so we don't need to override both ? ? ? ??
? ? @Override?
? ? public void write(byte[] buffer, int offset, int count)?
? ? ? ? ? ? throws IOException {?
? ? ? ? translateBuffer(buffer);?
? ? ? ? super.write(buffer, offset, count);?
? ? }?
}?
?
private class TranslateInputStream extends FileInputStream {?
?
? ? public TranslateInputStream(File file) throws FileNotFoundException {?
? ? ? ? super(file);?
? ? }?
?
? ? @Override?
? ? public int read() throws IOException {?
? ? ? ? return super.read() ^ MAGIC_NUMBER;?
? ? }?
?
? ? //In Android read(byte[]) calls this method so we don't need to override both ? ? ? ??
? ? @Override?
? ? public int read(byte[] buffer, int offset, int count)?
? ? ? ? ? ? throws IOException {?
? ? ? ? int bytesRead = super.read(buffer, offset, count);?
? ? ? ? translateBuffer(buffer);?
? ? ? ? return bytesRead;?
? ? }?
}?

热点排行