【发布时间】:2015-03-19 10:08:11
【问题描述】:
我的目标是,
我需要保护我的音频文件不受其他媒体播放器应用的影响。
在我的 android 媒体播放器应用程序中,可以选择下载歌曲。当我将其保存在内部/外部存储中时,此音频需要更加安全,而且此音频只能通过我的应用程序播放。所以我尝试加密我的音频文件并以 .txt 格式保存。为此我使用了这个代码sn-p,
加密
// Buffer used to transport the bytes from one stream to another
byte[] buf = new byte[1024];
/**
* Encrypt.
*
* @param in
* the in
* @param out
* the out
*/
public void encrypt(InputStream in, OutputStream out) {
try {
// Bytes written to out will be encrypted
out = new CipherOutputStream(out, ecipher);
// Read in the cleartext bytes and write to out to encrypt
int numRead = 0;
while ((numRead = in.read(buf)) >= 0) {
Log.e("encrypt - buffer - val", buf + "");
out.write(buf, 0, numRead);
}
out.close();
} catch (java.io.IOException e) {
e.printStackTrace();
}
}
**To Decrypt**
/**
* Decrypt.
*
* @param in
* the in
* @param out
* the out
*/
public void decrypt(InputStream in, OutputStream out) {
try {
// Bytes read from in will be decrypted
in = new CipherInputStream(in, dcipher);
// Read in the decrypted bytes and write the cleartext to out
int numRead = 0;
while ((numRead = in.read(buf)) >= 0) {
Log.e("decrypt - buffer - val", buf + "");
out.write(buf, 0, numRead);
}
out.close();
} catch (java.io.IOException e) {
e.printStackTrace();
}
}
这段代码对我来说很好用,我想知道还有其他方法可以实现我的目标吗?
【问题讨论】:
-
将文件保存在您的
/data/data/your.app.name/文件夹中,该文件夹对您的应用程序是私有的。 -
@DerGolem:当我将文件保存在这个位置时,其他音频播放器应用可以列出我的歌曲吗?
-
为什么要加密音乐?这将是一个缓慢的用户体验。
-
@DerGolem 为您提供了最佳解决方案。你为什么要隐藏音乐?
-
如果您将 MP3 添加到内部应用文件夹,则只有该应用可以看到它。您的整个问题现在已经从“保护”其他应用程序变为基本上为您的音乐添加 DRM。人们是否在您的应用中购买音乐?
标签: android