// Path: AndroidVault/vault/src/main/java/com/bottlerocketstudios/vault/keys/wrapper/SecretKeyWrapper.java
// public interface SecretKeyWrapper {
//     /**
//      * Wrap a {@link javax.crypto.SecretKey} using the public key assigned to this wrapper.
//      * Use {@link #unwrap(byte[], String)} to later recover the original
//      * {@link javax.crypto.SecretKey}.
//      *
//      * @return a wrapped version of the given {@link javax.crypto.SecretKey} that can be
//      * safely stored on untrusted storage.
//      */
//     byte[] wrap(SecretKey key) throws GeneralSecurityException, IOException;
// 
//     /**
//      * Unwrap a {@link javax.crypto.SecretKey} using the private key assigned to this
//      * wrapper.
//      *
//      * @param blob a wrapped {@link javax.crypto.SecretKey} as previously returned by
//      *             {@link #wrap(javax.crypto.SecretKey)}.
//      */
//     SecretKey unwrap(byte[] blob, String wrappedKeyAlgorithm) throws GeneralSecurityException, IOException;
// 
//     /**
//      * Change key material so that next wrapping will use a different key pair.
//      * @throws GeneralSecurityException
//      */
//     void clearKey(Context context) throws GeneralSecurityException, IOException;
// 
//     public KeyStorageType getKeyStorageType();
// }


import android.content.Context;
import android.content.SharedPreferences;
import android.util.Base64;
import android.util.Log;
import com.bottlerocketstudios.vault.keys.wrapper.SecretKeyWrapper;
import java.io.IOException;
import java.security.GeneralSecurityException;
import javax.crypto.SecretKey;
/*
 * Copyright (c) 2016. Bottle Rocket LLC
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.bottlerocketstudios.vault.keys.storage;





/**
 * Storage system using SharedPreference file to retain SecretKeys.
 */
public class SharedPrefKeyStorage implements KeyStorage {

    private static final String TAG = SharedPrefKeyStorage.class.getSimpleName();

    private static final String PREF_ROOT = "vaultedBlobV2.";

// Path: AndroidVault/vault/src/main/java/com/bottlerocketstudios/vault/keys/wrapper/SecretKeyWrapper.java
// public interface SecretKeyWrapper {
//     /**
//      * Wrap a {@link javax.crypto.SecretKey} using the public key assigned to this wrapper.
//      * Use {@link #unwrap(byte[], String)} to later recover the original
//      * {@link javax.crypto.SecretKey}.
//      *
//      * @return a wrapped version of the given {@link javax.crypto.SecretKey} that can be
//      * safely stored on untrusted storage.
//      */
//     byte[] wrap(SecretKey key) throws GeneralSecurityException, IOException;
// 
//     /**
//      * Unwrap a {@link javax.crypto.SecretKey} using the private key assigned to this
//      * wrapper.
//      *
//      * @param blob a wrapped {@link javax.crypto.SecretKey} as previously returned by
//      *             {@link #wrap(javax.crypto.SecretKey)}.
//      */
//     SecretKey unwrap(byte[] blob, String wrappedKeyAlgorithm) throws GeneralSecurityException, IOException;
// 
//     /**
//      * Change key material so that next wrapping will use a different key pair.
//      * @throws GeneralSecurityException
//      */
//     void clearKey(Context context) throws GeneralSecurityException, IOException;
// 
//     public KeyStorageType getKeyStorageType();
// }


// Path: AndroidVault/vault/src/main/java/com/bottlerocketstudios/vault/keys/storage/SharedPrefKeyStorage.java
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Base64;
import android.util.Log;
import com.bottlerocketstudios.vault.keys.wrapper.SecretKeyWrapper;
import java.io.IOException;
import java.security.GeneralSecurityException;
import javax.crypto.SecretKey;

/*
 * Copyright (c) 2016. Bottle Rocket LLC
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.bottlerocketstudios.vault.keys.storage;





/**
 * Storage system using SharedPreference file to retain SecretKeys.
 */
public class SharedPrefKeyStorage implements KeyStorage {

    private static final String TAG = SharedPrefKeyStorage.class.getSimpleName();

    private static final String PREF_ROOT = "vaultedBlobV2.";

    private final SecretKeyWrapper mSecretKeyWrapper;