use of java.security.Key in project sonarqube by SonarSource.
the class AesCipherTest method loadSecretKeyFromFile.
@Test
public void loadSecretKeyFromFile() throws Exception {
AesCipher cipher = new AesCipher(null);
Key secretKey = cipher.loadSecretFileFromFile(pathToSecretKey());
assertThat(secretKey.getAlgorithm()).isEqualTo("AES");
assertThat(secretKey.getEncoded().length).isGreaterThan(10);
}
use of java.security.Key in project sonarqube by SonarSource.
the class AesCipherTest method loadSecretKeyFromFile_trim_content.
@Test
public void loadSecretKeyFromFile_trim_content() throws Exception {
URL resource = getClass().getResource("/org/sonar/api/config/AesCipherTest/non_trimmed_secret_key.txt");
String path = new File(resource.toURI()).getCanonicalPath();
AesCipher cipher = new AesCipher(null);
Key secretKey = cipher.loadSecretFileFromFile(path);
assertThat(secretKey.getAlgorithm()).isEqualTo("AES");
assertThat(secretKey.getEncoded().length).isGreaterThan(10);
}
use of java.security.Key in project sonarqube by SonarSource.
the class AesCipherTest method loadSecretKeyFromFile_trim_content.
@Test
public void loadSecretKeyFromFile_trim_content() throws Exception {
String path = getPath("non_trimmed_secret_key.txt");
AesCipher cipher = new AesCipher(null);
Key secretKey = cipher.loadSecretFileFromFile(path);
assertThat(secretKey.getAlgorithm()).isEqualTo("AES");
assertThat(secretKey.getEncoded().length).isGreaterThan(10);
}
use of java.security.Key in project sonarqube by SonarSource.
the class AesCipherTest method loadSecretKeyFromFile.
@Test
public void loadSecretKeyFromFile() throws Exception {
AesCipher cipher = new AesCipher(null);
Key secretKey = cipher.loadSecretFileFromFile(pathToSecretKey());
assertThat(secretKey.getAlgorithm()).isEqualTo("AES");
assertThat(secretKey.getEncoded().length).isGreaterThan(10);
}
use of java.security.Key in project android_frameworks_base by ParanoidAndroid.
the class AndroidKeyStoreTest method testKeyStore_GetKey_NoPassword_Encrypted_Success.
public void testKeyStore_GetKey_NoPassword_Encrypted_Success() throws Exception {
setupPassword();
mKeyStore.load(null, null);
assertTrue(mAndroidKeyStore.importKey(Credentials.USER_PRIVATE_KEY + TEST_ALIAS_1, FAKE_KEY_1, KeyStore.UID_SELF, KeyStore.FLAG_ENCRYPTED));
assertTrue(mAndroidKeyStore.put(Credentials.USER_CERTIFICATE + TEST_ALIAS_1, FAKE_USER_1, KeyStore.UID_SELF, KeyStore.FLAG_ENCRYPTED));
assertTrue(mAndroidKeyStore.put(Credentials.CA_CERTIFICATE + TEST_ALIAS_1, FAKE_CA_1, KeyStore.UID_SELF, KeyStore.FLAG_ENCRYPTED));
Key key = mKeyStore.getKey(TEST_ALIAS_1, null);
assertNotNull("Key should exist", key);
assertTrue("Should be a RSAPrivateKey", key instanceof RSAPrivateKey);
RSAPrivateKey actualKey = (RSAPrivateKey) key;
KeyFactory keyFact = KeyFactory.getInstance("RSA");
PrivateKey expectedKey = keyFact.generatePrivate(new PKCS8EncodedKeySpec(FAKE_KEY_1));
assertEquals("Inserted key should be same as retrieved key", ((RSAPrivateKey) expectedKey).getModulus(), actualKey.getModulus());
}
Aggregations