diff options
author | Oscar Montemayor <oam@google.com> | 2010-01-14 16:38:40 -0800 |
---|---|---|
committer | Oscar Montemayor <oam@google.com> | 2010-01-15 11:16:31 -0800 |
commit | b62e8132df0d19a39a700324475b3df2de78e0b0 (patch) | |
tree | e5679e990fc995de73fc2c35dd03082c0efd7ebb /keystore/java/android/security/SystemKeyStore.java | |
parent | 013b9c249dbcb5ca293c5cfe6a0e7908ced32418 (diff) | |
download | frameworks_base-b62e8132df0d19a39a700324475b3df2de78e0b0.zip frameworks_base-b62e8132df0d19a39a700324475b3df2de78e0b0.tar.gz frameworks_base-b62e8132df0d19a39a700324475b3df2de78e0b0.tar.bz2 |
Apps on SD card.
Added support for retrieving and generating keys as Hex Strings.
Diffstat (limited to 'keystore/java/android/security/SystemKeyStore.java')
-rw-r--r-- | keystore/java/android/security/SystemKeyStore.java | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/keystore/java/android/security/SystemKeyStore.java b/keystore/java/android/security/SystemKeyStore.java index 452125a..61a4293 100644 --- a/keystore/java/android/security/SystemKeyStore.java +++ b/keystore/java/android/security/SystemKeyStore.java @@ -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); |