// Path: AndroidVault/vault/src/main/java/com/bottlerocketstudios/vault/EncryptionConstants.java
// public class EncryptionConstants {
//     public static final String AES_CIPHER = "AES";
//     public static final String BLOCK_MODE_CBC = "CBC";
//     public static final String ENCRYPTION_PADDING_PKCS5 = "PKCS5Padding";
//     public static final String ENCRYPTION_PADDING_PKCS7 = "PKCS7Padding";
// 
//     /**
//       * While this specifies PKCS5Padding and a 256 bit key, a historical artifact in the Sun encryption
//       * implementation interprets PKCS5 to be PKCS7 for block sizes over 8 bytes. In Android M this
//       * appears to have been corrected so that PKCS7Padding will work when instantiating a Cipher object.
//       */
//     public static final String AES_CBC_PADDED_TRANSFORM = AES_CIPHER + "/" + BLOCK_MODE_CBC + "/" + ENCRYPTION_PADDING_PKCS5;
//     public static final String AES_CBC_PADDED_TRANSFORM_ANDROID_M = AES_CIPHER + "/" + BLOCK_MODE_CBC + "/" + ENCRYPTION_PADDING_PKCS7;
//     public static final int AES_256_KEY_LENGTH_BITS = 256;
// 
//     public static final String DIGEST_SHA256 = "SHA256";
// 
//     public static final String ANDROID_KEY_STORE = "AndroidKeyStore";
// }
// 
// Path: AndroidVault/vault/src/main/java/com/bottlerocketstudios/vault/keys/generator/Aes256RandomKeyFactory.java
// public class Aes256RandomKeyFactory {
// 
//     /**
//      * Create a randomly generated AES256 key.
//      */
//     public static SecretKey createKey() {
//         RandomKeyGenerator keyGenerator = new RandomKeyGenerator(new PrngSaltGenerator(), EncryptionConstants.AES_256_KEY_LENGTH_BITS);
//         return keyGenerator.generateKey(EncryptionConstants.AES_CIPHER);
//     }
// }
// 
// Path: AndroidVault/vault/src/main/java/com/bottlerocketstudios/vault/salt/PrngSaltGenerator.java
// public class PrngSaltGenerator implements SaltGenerator {
// 
//     SecureRandom mSecureRandom;
// 
//     public PrngSaltGenerator() {
//         mSecureRandom = new SecureRandom();
//     }
// 
//     @Override
//     public byte[] createSaltBytes(int size) {
//         byte[] result = new byte[size];
//         mSecureRandom.nextBytes(result);
//         return result;
//     }
// }


import android.os.Build;
import android.test.AndroidTestCase;
import android.util.Log;
import com.bottlerocketstudios.vault.EncryptionConstants;
import com.bottlerocketstudios.vault.keys.generator.Aes256RandomKeyFactory;
import com.bottlerocketstudios.vault.salt.PrngSaltGenerator;
import java.security.GeneralSecurityException;
import java.util.Arrays;
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;





/**
 * Created on 9/21/16.
 */
public class TestVaultOaepUpgrade extends AndroidTestCase {
    private static final String TAG = TestVaultUpgradePre18.class.getSimpleName();

    private static final String KEY_FILE_NAME = "OaepUpgradeKeyFile";
    private static final String KEY_ALIAS_1 = "OaepUpgradeKeyAlias";
    private static final int KEY_INDEX_1 = 1223422;
    private static final String PRESHARED_SECRET_1 = "a;sdlfkja;asdfa4548w1211xji22e;l2ihjl9jl9dj9";

    public void testUpgrade() {
        assertTrue("This test will not pass below API 23", Build.VERSION.SDK_INT >= Build.VERSION_CODES.M);
        try {
// Path: AndroidVault/vault/src/main/java/com/bottlerocketstudios/vault/EncryptionConstants.java
// public class EncryptionConstants {
//     public static final String AES_CIPHER = "AES";
//     public static final String BLOCK_MODE_CBC = "CBC";
//     public static final String ENCRYPTION_PADDING_PKCS5 = "PKCS5Padding";
//     public static final String ENCRYPTION_PADDING_PKCS7 = "PKCS7Padding";
// 
//     /**
//       * While this specifies PKCS5Padding and a 256 bit key, a historical artifact in the Sun encryption
//       * implementation interprets PKCS5 to be PKCS7 for block sizes over 8 bytes. In Android M this
//       * appears to have been corrected so that PKCS7Padding will work when instantiating a Cipher object.
//       */
//     public static final String AES_CBC_PADDED_TRANSFORM = AES_CIPHER + "/" + BLOCK_MODE_CBC + "/" + ENCRYPTION_PADDING_PKCS5;
//     public static final String AES_CBC_PADDED_TRANSFORM_ANDROID_M = AES_CIPHER + "/" + BLOCK_MODE_CBC + "/" + ENCRYPTION_PADDING_PKCS7;
//     public static final int AES_256_KEY_LENGTH_BITS = 256;
// 
//     public static final String DIGEST_SHA256 = "SHA256";
// 
//     public static final String ANDROID_KEY_STORE = "AndroidKeyStore";
// }
// 
// Path: AndroidVault/vault/src/main/java/com/bottlerocketstudios/vault/keys/generator/Aes256RandomKeyFactory.java
// public class Aes256RandomKeyFactory {
// 
//     /**
//      * Create a randomly generated AES256 key.
//      */
//     public static SecretKey createKey() {
//         RandomKeyGenerator keyGenerator = new RandomKeyGenerator(new PrngSaltGenerator(), EncryptionConstants.AES_256_KEY_LENGTH_BITS);
//         return keyGenerator.generateKey(EncryptionConstants.AES_CIPHER);
//     }
// }
// 
// Path: AndroidVault/vault/src/main/java/com/bottlerocketstudios/vault/salt/PrngSaltGenerator.java
// public class PrngSaltGenerator implements SaltGenerator {
// 
//     SecureRandom mSecureRandom;
// 
//     public PrngSaltGenerator() {
//         mSecureRandom = new SecureRandom();
//     }
// 
//     @Override
//     public byte[] createSaltBytes(int size) {
//         byte[] result = new byte[size];
//         mSecureRandom.nextBytes(result);
//         return result;
//     }
// }


// Path: AndroidVault/vault/src/androidTest/java/com/bottlerocketstudios/vault/keys/storage/TestVaultOaepUpgrade.java
import android.os.Build;
import android.test.AndroidTestCase;
import android.util.Log;
import com.bottlerocketstudios.vault.EncryptionConstants;
import com.bottlerocketstudios.vault.keys.generator.Aes256RandomKeyFactory;
import com.bottlerocketstudios.vault.salt.PrngSaltGenerator;
import java.security.GeneralSecurityException;
import java.util.Arrays;
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;





/**
 * Created on 9/21/16.
 */
public class TestVaultOaepUpgrade extends AndroidTestCase {
    private static final String TAG = TestVaultUpgradePre18.class.getSimpleName();

    private static final String KEY_FILE_NAME = "OaepUpgradeKeyFile";
    private static final String KEY_ALIAS_1 = "OaepUpgradeKeyAlias";
    private static final int KEY_INDEX_1 = 1223422;
    private static final String PRESHARED_SECRET_1 = "a;sdlfkja;asdfa4548w1211xji22e;l2ihjl9jl9dj9";

    public void testUpgrade() {
        assertTrue("This test will not pass below API 23", Build.VERSION.SDK_INT >= Build.VERSION_CODES.M);
        try {
            SecretKey originalKey = Aes256RandomKeyFactory.createKey();