小编use*_*273的帖子

如何在Android中使用AES加密SD卡中的文件?

我想从SD卡加密图像并使用AES再次将其存储在SD卡中.主要思想是应用程序浏览图像,然后在按下按钮时对其进行加密,然后将其存储在SD卡中.所以我的形象是安全的.

我已经成功使用本教程http://www.androidsnippets.com/encryptdecrypt-strings中的 AES进行字符串加密,但我不知道如何使用图像而不是字符串来完成此操作.

这是我用字符串做的方式:

public static String encrypt(String seed, String cleartext) throws Exception  
{
    byte[] rawKey = getRawKey(seed.getBytes());
    byte[] result = encrypt(rawKey, cleartext.getBytes()); 
    return toHex(result);
}

private static byte[] encrypt(byte[] raw, byte[] clear) throws Exception 
{
    SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
    Cipher cipher = Cipher.getInstance("AES");
    cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
    byte[] encrypted = cipher.doFinal(clear);
    return encrypted;
}
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮我提供示例代码如何使用AES 加密图像

也许它必须使用I/O文件流,但我不知道如何使用此代码实现.

encryption android file aes

35
推荐指数
1
解决办法
4万
查看次数

标签 统计

aes ×1

android ×1

encryption ×1

file ×1