我有一堆视频文件需要放在Android平板电脑上作为我们应用程序的数据。因为我们不想轻松访问,所以我们决定加密视频。我通过默默无闻的方式来采取安全措施。我之前开始通过加密整个视频并在播放之前对其进行解密,但很快显而易见,加载视频是一个很大的保真杀手。用户体验和应用程序的流程被拍摄。部分文件加密
我想也许我可以加密视频的第一个MB,因为我们所有的视频都超过1MB。如果盗贼至少拿到了他们的视频,那么这不是整个事情,并且是无用的。
贝娄是加密和解密文件的代码。它的工作原理除了视频,因为我试图将文件的两个部分拼凑在一起。加密文件看起来很好。解密的文件在一个地方关闭。我想通过差异测试来运行它们。
public void encrypt(InputStream in, OutputStream out) {
try {
// Bytes written to out will be encrypted
OutputStream out_c = new CipherOutputStream(out, ecipher);
// Read in the cleartext bytes and write to out to encrypt
int numRead = 0;
int count = 0;
boolean first = true;
while ((numRead = in.read(buf)) >= 0) {
if(count <= 1048576){
count += numRead;
out_c.write(buf, 0, numRead);
}else{
out.write(buf, 0, numRead);
}
}
out.close();
out_c.close();
} catch (java.io.IOException e) {
}
}
// Movies encrypt only 1 MB.
public void decrypt(InputStream in, OutputStream out) {
try {
// Bytes read from in will be decrypted
InputStream in_c = new CipherInputStream(in, dcipher);
// Read in the decrypted bytes and write the cleartext to out
int numRead = 0;
int count = 0;
while ((numRead = in_c.read(buf)) >= 0 && count <= 1048576) {
count += numRead;
out.write(buf, 0, numRead);
}
//in.skip(count); This removed 1MB from the final file. No need to skip.
while((numRead = in.read(buf)) >= 0){
out.write(buf,0,numRead);
}
out.close();
} catch (java.io.IOException e) {
}
}
我想知道是否有人可以发现加密或解密的问题。我知道这不是一个理想的解决方案,但它适用于我们的情况。
谢谢。
我不确定我是否理解你的问题。您提供的代码适用于某些文件,但不适用于视频文件?使用哪种视频(mpeg?)它不起作用?它工作,如果你使用整个文件的程序,而不是1兆? – woliveirajr 2012-03-26 20:35:39
你问的是错误的问题。问题应该是:如何阻止Android用户复制我的视频?这就是[DRM api](http://developer.android.com/reference/android/drm/package-summary.html)的用途。 – mikerobi 2012-03-26 20:47:29