org.springframework.security.rsa.crypto.KeyStoreKeyFactory Java Examples

The following examples show how to use org.springframework.security.rsa.crypto.KeyStoreKeyFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EncryptionBootstrapConfiguration.java    From spring-cloud-commons with Apache License 2.0 6 votes vote down vote up
@Bean
@ConditionalOnMissingBean(TextEncryptor.class)
public TextEncryptor textEncryptor() {
	KeyStore keyStore = this.key.getKeyStore();
	if (keyStore.getLocation() != null) {
		if (keyStore.getLocation().exists()) {
			return new RsaSecretEncryptor(
					new KeyStoreKeyFactory(keyStore.getLocation(),
							keyStore.getPassword().toCharArray()).getKeyPair(
									keyStore.getAlias(),
									keyStore.getSecret().toCharArray()),
					this.rsaProperties.getAlgorithm(),
					this.rsaProperties.getSalt(), this.rsaProperties.isStrong());
		}

		throw new IllegalStateException("Invalid keystore location");
	}

	return new EncryptorFactory(this.key.getSalt()).create(this.key.getKey());
}
 
Example #2
Source File: SecurityTokenProvider.java    From cms with Apache License 2.0 5 votes vote down vote up
@Bean
public KeyPair getKeyPair() {
    ClassPathResource resource = new ClassPathResource(properties.getKeyStore());
    char[] keyStorePassword = properties.getKeyStorePassword().toCharArray();
    char[] keyPassword = properties.getKeyPassword().toCharArray();
    String keyAlias = properties.getKeyAlias();
    KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(resource, keyStorePassword);
    return keyStoreKeyFactory.getKeyPair(keyAlias, keyPassword);
}
 
Example #3
Source File: DecryptCommandTests.java    From spring-cloud-cli with Apache License 2.0 5 votes vote down vote up
@Test
public void decryptsFromRsaKeyWithKeyStore() throws Exception {
	KeyStoreKeyFactory factory = new KeyStoreKeyFactory(
			new ClassPathResource("keystore.jks"), "letmein".toCharArray());
	RsaSecretEncryptor encryptor = new RsaSecretEncryptor(
			factory.getKeyPair("mytestkey", "changeme".toCharArray()));
	String cipher = encryptor.encrypt("foo");
	assertEquals(ExitStatus.OK,
			command.run("-k", "src/test/resources/keystore.jks", "--password",
					"letmein", "--keypass", "changeme", "--alias", "mytestkey",
					cipher));
}
 
Example #4
Source File: EncryptionAutoConfiguration.java    From spring-cloud-config with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public TextEncryptorLocator textEncryptorLocator() {
	KeyStore keyStore = this.key.getKeyStore();
	KeyStoreTextEncryptorLocator locator = new KeyStoreTextEncryptorLocator(
			new KeyStoreKeyFactory(keyStore.getLocation(),
					keyStore.getPassword().toCharArray(),
					key.getKeyStore().getType()),
			keyStore.getSecret(), keyStore.getAlias());
	RsaAlgorithm algorithm = this.rsaProperties.getAlgorithm();
	locator.setRsaAlgorithm(algorithm);
	locator.setSalt(this.rsaProperties.getSalt());
	locator.setStrong(this.rsaProperties.isStrong());
	return locator;
}
 
Example #5
Source File: KeyStoreTextEncryptorLocator.java    From spring-cloud-config with Apache License 2.0 4 votes vote down vote up
public KeyStoreTextEncryptorLocator(KeyStoreKeyFactory keys, String defaultSecret,
		String defaultAlias) {
	this.keys = keys;
	this.defaultAlias = defaultAlias;
	this.defaultSecret = defaultSecret;
}