我正在使用加密制作一个安全的视频播放应用程序。在我的应用程序加密完成但它不能在我的VideoView中播放。没有显示错误。我希望当我点击该按钮时,视频将加密并保存在存储和播放中而不保存解密文件。但我无法做到这一点。请帮助我。告诉我我的代码中的问题在哪里。感谢
这是我的java代码
encryptButton = (Button) findViewById(R.id.button);
mVideoView = (VideoView) findViewById(R.id.vwVideo);
mVideoView.setOnCompletionListener(this);
encryptButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
encrypt();
} catch (Exception e) {
e.printStackTrace();
}
Toast.makeText(getApplicationContext(), " Encryption complete ",
Toast.LENGTH_SHORT).show();
}
});
File file = new File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES),
"/storage/emulated/0/DCIM/Camera/encrypt.mp4");
mVideoView.setOnCompletionListener(this);
mVideoView.setMediaController(new MediaController(this));
try {
mServer = new LocalSingleHttpServer();
mServer.setCipher(myGetCipher());
mServer.start();
String path = mServer.getURL(file.getPath());
mVideoView.setVideoPath(path);
mVideoView.start();
} catch (Exception e) {
// Auto-generated catch block
e.printStackTrace();
}
}
private Cipher myGetCipher() throws NoSuchPaddingException, NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException {
// avoid the default security provider "AndroidOpenSSL" in Android 4.3+ (http://libeasy.alwaysdata.net/network/#provider)
Cipher c = Cipher.getInstance("ARC4", "BC");
c.init(Cipher.DECRYPT_MODE, new SecretKeySpec("BrianIsInTheKitchen".getBytes(), "ARC4"));
return c;
}
public static void encrypt() throws Exception {
final byte[] buf = new byte[8192];
final Cipher c = Cipher.getInstance("AES/CTR/NoPadding");
c.init(Cipher.ENCRYPT_MODE, new SecretKeySpec("1234567890123456".getBytes(), "AES"), new IvParameterSpec(new byte[16]));
final InputStream is = new FileInputStream("/storage/emulated/0/DCIM/Camera/VID_20140217_144346.mp4");
final OutputStream os = new CipherOutputStream(new FileOutputStream("/storage/emulated/0/DCIM/Camera/encrypt.mp4"), c);
while (true) {
int n = is.read(buf);
if (n == -1) break;
os.write(buf, 0, n);
}
os.close();
is.close();
}
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
mServer.stop();
}