Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android-如何在本地存储和检索SecretKey对象并检索它_Android_Encryption_Cryptography_Secret Key - Fatal编程技术网

Android-如何在本地存储和检索SecretKey对象并检索它

Android-如何在本地存储和检索SecretKey对象并检索它,android,encryption,cryptography,secret-key,Android,Encryption,Cryptography,Secret Key,我正在创建一个应用程序,应该允许音频文件的加密。我正在创建一个SecretKey对象,并使用它来加密和解密文件。一切正常,但现在我需要一种方法来本地存储SecretKey对象,以便在再次打开应用程序时,可以使用它来解密数据 我尝试了以下几种方法: final byte[] filesBytes = encodeFile(mySecretKey, stringToSave); SharedPreferences settings = context.getSharedPreferences(KEY

我正在创建一个应用程序,应该允许音频文件的加密。我正在创建一个SecretKey对象,并使用它来加密和解密文件。一切正常,但现在我需要一种方法来本地存储SecretKey对象,以便在再次打开应用程序时,可以使用它来解密数据

我尝试了以下几种方法:

final byte[] filesBytes = encodeFile(mySecretKey, stringToSave);
SharedPreferences settings = context.getSharedPreferences(KEY_PREFS, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("cryptoKey", Arrays.toString(filesBytes));
SharedPreferences settings = context.getSharedPreferences(KEY_PREFS, 0);
    String stringArray = settings.getString("cryptoKey", null);

    if (stringArray != null) {
        String[] split = stringArray.substring(1, stringArray.length() - 1).split(", ");
        byte[] array = new byte[split.length];
        for (int i = 0; i < split.length; i++) {
            array[i] = Byte.parseByte(split[i]);
        }
        localSecretKey = new SecretKeySpec(array, "AES");
    }
为了检索数据,我正在尝试以下操作:

final byte[] filesBytes = encodeFile(mySecretKey, stringToSave);
SharedPreferences settings = context.getSharedPreferences(KEY_PREFS, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("cryptoKey", Arrays.toString(filesBytes));
SharedPreferences settings = context.getSharedPreferences(KEY_PREFS, 0);
    String stringArray = settings.getString("cryptoKey", null);

    if (stringArray != null) {
        String[] split = stringArray.substring(1, stringArray.length() - 1).split(", ");
        byte[] array = new byte[split.length];
        for (int i = 0; i < split.length; i++) {
            array[i] = Byte.parseByte(split[i]);
        }
        localSecretKey = new SecretKeySpec(array, "AES");
    }
SharedReferences settings=context.getSharedReferences(KEY\u PREFS,0);
String stringArray=settings.getString(“加密密钥”,null);
if(stringArray!=null){
String[]split=stringArray.substring(1,stringArray.length()-1);
字节[]数组=新字节[split.length];
对于(int i=0;i
我还看了一些帖子,比如:which't have not help


我需要知道的是,如何在本地存储SecretKey对象,以便在以后重新打开应用程序时检索它?

您没有指出实际问题所在。请编辑您的问题并加以改进。将密钥存储在密钥存储中通常是一个不错的解决方案,为什么这对您没有帮助?我已编辑了该问题。我的问题是,我需要知道如何本地存储SecretKey对象。mySecretKey.getEncoded()是否适合您?