use of com.radixdlt.crypto.exception.KeyStoreException in project radixdlt by radixdlt.
the class RadixKeyStore method fromFile.
/**
* Load a private key from file, and compute the public key.
*
* <p>Note that if {@code create} is set to {@code true}, then the file will be created if it does
* not exist. If the file is created, then it's permissions will be set to just {@link
* PosixFilePermission#OWNER_READ} and {@link PosixFilePermission#OWNER_WRITE} on Posix
* filesystems.
*
* @param file The file to load the private key from
* @param storePassword The password to use for securing the store. Set to {@code null} if a
* default password should be used. Note: using {@code null} effectively means there is
* <b><i>no security</i></b> on the underlying key store.
* @param create Set to {@code true} if the file should be created if it doesn't exist.
* @return A {@link RadixKeyStore}
* @throws IOException If reading or writing the file fails
* @throws KeyStoreException If the key read from the file is invalid
*/
public static RadixKeyStore fromFile(File file, char[] storePassword, boolean create) throws IOException, KeyStoreException {
try {
var ks = KeyStore.getInstance("pkcs12");
var usedStorePassword = (storePassword == null || storePassword.length == 0) ? defaultKey : storePassword;
initializeKeyStore(ks, file, usedStorePassword, create);
return new RadixKeyStore(file, ks, usedStorePassword.clone());
} catch (GeneralSecurityException ex) {
throw new KeyStoreException("Can't load key store", ex);
}
}
use of com.radixdlt.crypto.exception.KeyStoreException in project radixdlt by radixdlt.
the class RadixKeyStoreTest method testClose.
/**
* Test method for {@link RadixKeyStore#close()}.
*/
@Test
public void testClose() throws IOException, KeyStoreException {
File file = newFile(TEST_KS_FILENAME);
@SuppressWarnings("resource") RadixKeyStore ks = RadixKeyStore.fromFile(file, "testpassword".toCharArray(), true);
assertTrue(file.exists());
ks.close();
char[] pwd = ks.storePassword();
assertEquals(12, pwd.length);
assertTrue(IntStream.range(0, pwd.length).map(i -> pwd[i]).allMatch(i -> i == ' '));
}
Aggregations