关于Android中的加密和解密文件?

时间:2015-11-22 12:15:56

标签: android aes

我读了一篇关于AES的文章。然后我尝试解密AES,但它似乎不起作用。这是我的代码:

public static byte[] loadFile(String sourcePath) throws IOException{
    InputStream inputStream = null;
     try 
     {
         inputStream = new FileInputStream(sourcePath);
         return readFully(inputStream);
     } 
     finally
     {
         if (inputStream != null)
         {
             inputStream.close();
         }
     }
 }



public static byte[] readFully(InputStream stream) throws IOException
{



    byte[] buffer = new byte[8192];
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    int bytesRead;
    while ((bytesRead = stream.read(buffer)) != -1)
    {
        baos.write(buffer, 0, bytesRead);
    }
    return baos.toByteArray();
}
String decodeFile() {
    String str = null;
    try {


        byte[] decodedData = decodeFile(yourKey,loadFile(Environment.getExternalStorageDirectory().toString()+ "/" + encryptedFileName));
         str = new String(decodedData);

         Toast.makeText(getApplicationContext(), 
              str, 
                     Toast.LENGTH_LONG).show();

         text2=(TextView)findViewById(R.id.textView2);
         text2.setText(str);

    } catch (Exception e) {
        e.printStackTrace();
    }
    return str;
}

任何人都可以说,为什么不呢?

0 个答案:

没有答案