[英]how to play encrypted video in videoview without decrypt
In my app i want to play video with encryption, for security purpose that the video could not played by other app.I already encrypt and decrypt video and saved in external storage but I can't play it. 为了安全起见,我想在我的应用中播放加密视频,因为其他应用无法播放该视频。我已经加密和解密了视频并保存在外部存储中,但是无法播放。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button encryptButton = (Button) findViewById(R.id.button);
encryptButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
encrypt();
Toast.makeText(getApplicationContext(), " Encryption complete ",
Toast.LENGTH_SHORT).show();
}catch (InvalidKeyException e){
e.printStackTrace();
}catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
});
}
static void encrypt() throws IOException, NoSuchAlgorithmException,
NoSuchPaddingException, InvalidKeyException{
FileInputStream fis = new FileInputStream(new File("/storage/emulated/0/DCIM/Camera/VID_20140217_144346.mp4"));
File outfile = new File("/storage/emulated/0/DCIM/Camera/encrypt.mp4");
int read;
if(!outfile.exists())
outfile.createNewFile();
File decfile = new File("/storage/emulated/0/DCIM/Camera/decrypt.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");
//byte key[] = {0x00,0x32,0x22,0x11,0x00,0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
SecretKey skey = kgen.generateKey();
//Lgo
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();
}
I want when that button clicked that video encrypt and play that video. 我想要当该按钮单击该视频时加密并播放该视频。 That video can played only inside the app.
该视频只能在应用内播放。 I search many thing but can't understand properly.
我搜索了很多东西,但无法正确理解。 Please help me.
请帮我。 Thanks.
谢谢。
Hello Here is a third party library to play encrypted videos on the fly. 您好,这里是一个第三方库,可以即时播放加密的视频。
http://libeasy.alwaysdata.net/network/#encoding http://libeasy.alwaysdata.net/network/#encoding
It make the local server and serve the frames of video in chunks to the Videoview. 它构成本地服务器,并将视频帧分块提供给Videoview。 For now I only found this library that suits your requirement.
现在,我只找到了适合您需求的库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.