Apps on SD card.
Added support for retrieving and generating keys as Hex Strings.
This commit is contained in:
@@ -35,6 +35,7 @@ import javax.crypto.SecretKey;
|
||||
public class SystemKeyStore {
|
||||
|
||||
private static final String SYSTEM_KEYSTORE_DIRECTORY = "misc/systemkeys";
|
||||
private static final String KEY_FILE_EXTENSION = ".sks";
|
||||
private static SystemKeyStore mInstance = new SystemKeyStore();
|
||||
|
||||
private SystemKeyStore() { }
|
||||
@@ -43,6 +44,28 @@ public class SystemKeyStore {
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
public static String toHexString(byte[] keyData) {
|
||||
if (keyData == null) {
|
||||
return null;
|
||||
}
|
||||
int keyLen = keyData.length;
|
||||
int expectedStringLen = keyData.length * 2;
|
||||
StringBuilder sb = new StringBuilder(expectedStringLen);
|
||||
for (int i = 0; i < keyData.length; i++) {
|
||||
String hexStr = Integer.toString(keyData[i] & 0x00FF, 16);
|
||||
if (hexStr.length() == 1) {
|
||||
hexStr = "0" + hexStr;
|
||||
}
|
||||
sb.append(hexStr);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String generateNewKeyHexString(int numBits, String algName, String keyName)
|
||||
throws NoSuchAlgorithmException {
|
||||
return toHexString(generateNewKey(numBits, algName, keyName));
|
||||
}
|
||||
|
||||
public byte[] generateNewKey(int numBits, String algName, String keyName)
|
||||
throws NoSuchAlgorithmException {
|
||||
|
||||
@@ -78,10 +101,14 @@ public class SystemKeyStore {
|
||||
private File getKeyFile(String keyName) {
|
||||
File sysKeystoreDir = new File(Environment.getDataDirectory(),
|
||||
SYSTEM_KEYSTORE_DIRECTORY);
|
||||
File keyFile = new File(sysKeystoreDir, keyName);
|
||||
File keyFile = new File(sysKeystoreDir, keyName + KEY_FILE_EXTENSION);
|
||||
return keyFile;
|
||||
}
|
||||
|
||||
public String retrieveKeyHexString(String keyName) {
|
||||
return toHexString(retrieveKey(keyName));
|
||||
}
|
||||
|
||||
public byte[] retrieveKey(String keyName) {
|
||||
|
||||
File keyFile = getKeyFile(keyName);
|
||||
|
||||
Reference in New Issue
Block a user