小编Mat*_*ing的帖子

在Android上加密图像文件 - 密码(输出|输入)流问题

我正在尝试使用基于密码的加密来加密Android上的图像文件.要保存加密图像,我只需这样做:

FileOutputStream fos = new FileOutputStream(thumbnailFile);
CipherOutputStream cos = new CipherOutputStream(fos, encryptCipher);
Bitmap thumbnail = Bitmap.createScaledBitmap(bm2, 140, 140, true);
thumbnail.compress(Bitmap.CompressFormat.JPEG, 80, cos);
Run Code Online (Sandbox Code Playgroud)

并阅读它,这:

FileInputStream fis = new FileInputStream(f);
CipherInputStream cis = new CipherInputStream(fis, decryptCipher);
Bitmap b = BitmapFactory.decodeStream(cis);
Run Code Online (Sandbox Code Playgroud)

但是Bitmap最终为null.当我绕过加密时代码有效; 那是我使用文件(输入|输出)流而不是密码(输入|输出)流.

我的密码创建如下:

public void initCiphers(char password[]) {

PBEKeySpec pbeKeySpec;
PBEParameterSpec pbeParamSpec;
SecretKeyFactory keyFac;

byte[] salt = {
   (byte)0xc7, (byte)0x73, (byte)0x21, (byte)0x8c,
   (byte)0x7e, (byte)0xc8, (byte)0xee, (byte)0x99
};
int count = 20;
pbeParamSpec = new PBEParameterSpec(salt, count);          
pbeKeySpec = new PBEKeySpec(password);
try { …
Run Code Online (Sandbox Code Playgroud)

java android

13
推荐指数
1
解决办法
4032
查看次数

标签 统计

android ×1

java ×1