我在互联网上找到了这个代码并在java上正常工作,但在android中我得到错误而且我不理解它。
我有"error opening trace file: No such file or directory (2)"
的错误。
如果你帮助我会很感激!
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_aeshelper);
Button btn = (Button) findViewById(R.id.button1);
final String FileDir = "data/";
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
try {
FileInputStream fis = new FileInputStream(new File(FileDir+"aaa.mp4"));
File outfile = new File(FileDir + "EncryptedVideo.mp4");
int read;
if (!outfile.exists())
outfile.createNewFile();
File decfile = new File(FileDir + "DecryptedVideo.mp4");
if (!decfile.exists())
decfile.createNewFile();
FileOutputStream fos = new FileOutputStream(outfile);
FileInputStream encfis = new FileInputStream(outfile);
FileOutputStream decfos = new FileOutputStream(decfile);
Cipher encipher = Cipher.getInstance("AES");
Cipher decipher = Cipher.getInstance("AES");
KeyGenerator kgen = KeyGenerator.getInstance("AES");
SecretKey skey = kgen.generateKey();
encipher.init(Cipher.ENCRYPT_MODE, skey);
CipherInputStream cis = new CipherInputStream(fis, encipher);
decipher.init(Cipher.DECRYPT_MODE, skey);
CipherOutputStream cos = new CipherOutputStream(decfos, decipher);
while ((read = cis.read()) != -1) {
fos.write((char) read);
fos.flush();
}
fos.close();
while ((read = encfis.read()) != -1) {
cos.write(read);
cos.flush();
}
cos.close();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),"!!!",
Toast.LENGTH_LONG).show(); }
}
});
}
}