gpt4 book ai didi

android - 如何在视频 View 中播放加密视频而不解密

转载 作者:行者123 更新时间:2023-11-29 18:57:51 24 4
gpt4 key购买 nike

为了安全起见,我想在我的应用中播放加密的视频,以确保其他应用无法播放该视频。我已经加密和解密了视频并保存在外部存储中,但无法播放。

@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();
}


我想要当该按钮单击该视频时加密并播放该视频。该视频只能在应用内播放。我搜索了很多东西,但无法正确理解。请帮我。谢谢。

最佳答案

您好,这里是一个第三方库,可以即时播放加密的视频。

http://libeasy.alwaysdata.net/network/#encoding

它构成本地服务器,并将视频帧分块提供给Videoview。现在,我只找到了适合您需求的库。

关于android - 如何在视频 View 中播放加密视频而不解密,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49631889/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com