本文整理匯總了Java中org.springframework.security.crypto.encrypt.Encryptors類的典型用法代碼示例。如果您正苦於以下問題:Java Encryptors類的具體用法?Java Encryptors怎麽用?Java Encryptors使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Encryptors類屬於org.springframework.security.crypto.encrypt包,在下文中一共展示了Encryptors類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testDecryptNonStandardParent
import org.springframework.security.crypto.encrypt.Encryptors; //導入依賴的package包/類
@Test
public void testDecryptNonStandardParent() {
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext();
EnvironmentDecryptApplicationInitializer initializer = new EnvironmentDecryptApplicationInitializer(
Encryptors.noOpText());
TestPropertyValues.of("key:{cipher}value").applyTo(ctx);
ApplicationContext ctxParent = mock(ApplicationContext.class);
when(ctxParent.getEnvironment()).thenReturn(mock(Environment.class));
ctx.setParent(ctxParent);
initializer.initialize(ctx);
assertEquals("value", ctx.getEnvironment().getProperty("key"));
}
開發者ID:spring-cloud,項目名稱:spring-cloud-commons,代碼行數:18,代碼來源:EnvironmentDecryptApplicationInitializerTests.java
示例2: encryptMessage
import org.springframework.security.crypto.encrypt.Encryptors; //導入依賴的package包/類
/**
* Gets a raw message, generates a new encryption key and encrypts the message
* @param message The object that contains the message to be encrypted
* @return The Message object with the encrypted message and the decryptedMessage field cleared
*/
Message encryptMessage(Message message)
{
Object credentials = Util.getCredentials();
// bcrypt: $version$cost$salthash, with 22 chars for salt
String cryptoKey = bCryptPasswordEncoder.encode(credentials.toString());
// Spring BCrypt considers version and cost as part of the salt, so:
String cryptoKeySalt = cryptoKey.substring(0, 29);
message.setCryptoKeySalt(cryptoKeySalt);
String cryptoSalt = KeyGenerators.string().generateKey();
message.setCryptoSalt(cryptoSalt);
String encryptedMessage = Encryptors.text(cryptoKey, cryptoSalt).encrypt(message.getDecryptedMessage());
message.setEncryptedMessage(encryptedMessage);
message.setDecryptedMessage("");
return message;
}
示例3: getUsersConnectionRepository
import org.springframework.security.crypto.encrypt.Encryptors; //導入依賴的package包/類
@Override
public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator connectionFactoryLocator) {
return new JdbcUsersConnectionRepository(
dataSource,
connectionFactoryLocator,
/**
* The TextEncryptor object encrypts the authorization details of the connection. In
* our example, the authorization details are stored as plain text.
* DO NOT USE THIS IN PRODUCTION.
*/
Encryptors.noOpText()
);
}
示例4: encrypt
import org.springframework.security.crypto.encrypt.Encryptors; //導入依賴的package包/類
/**
* Method to encrypt fields based on {@link Encrypt} annotation.
*
* @param obj entity object
*/
public static void encrypt(Object obj) throws IllegalAccessException {
CharSequence salt = getSalt(obj);
TextEncryptor encryptor = Encryptors.text(secretKey, salt);
for (Field field : obj.getClass().getDeclaredFields()) {
if (field.isAnnotationPresent(Encrypt.class)) {
field.setAccessible(true);
field.set(obj, encryptor.encrypt((String) field.get(obj)));
field.setAccessible(false);
}
}
}
示例5: decrypt
import org.springframework.security.crypto.encrypt.Encryptors; //導入依賴的package包/類
/**
* Method to decrypt fields based on {@link Encrypt} annotation.
*
* @param obj entity object
*/
public static void decrypt(Object obj) throws IllegalAccessException {
CharSequence salt = getSalt(obj);
TextEncryptor encryptor = Encryptors.text(secretKey, salt);
for (Field field : obj.getClass().getDeclaredFields()) {
if (field.isAnnotationPresent(Encrypt.class)) {
field.setAccessible(true);
field.set(obj, encryptor.decrypt((String) field.get(obj)));
field.setAccessible(false);
}
}
}
示例6: getUsersConnectionRepository
import org.springframework.security.crypto.encrypt.Encryptors; //導入依賴的package包/類
@Override
public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator locator) {
UsersConnectionRepositoryTable.update(dataSource);
final JdbcUsersConnectionRepository repository = new JdbcUsersConnectionRepository(dataSource,
locator, Encryptors.noOpText());
repository.setConnectionSignUp(connectionSignUp);
return repository;
}
示例7: getUsersConnectionRepository
import org.springframework.security.crypto.encrypt.Encryptors; //導入依賴的package包/類
/**
* Singleton data access object providing access to connections across all users.
*/
@Override
public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator connectionFactoryLocator) {
JdbcUsersConnectionRepository repository = new JdbcUsersConnectionRepository(dataSource, connectionFactoryLocator, Encryptors.noOpText());
repository.setConnectionSignUp(new OpenTipBotConnectionSignUp(opentipbotUserService, bitcoinService));
return repository;
}
示例8: errorOnDecrypt
import org.springframework.security.crypto.encrypt.Encryptors; //導入依賴的package包/類
@Test(expected = IllegalStateException.class)
public void errorOnDecrypt() {
this.listener = new EnvironmentDecryptApplicationInitializer(
Encryptors.text("deadbeef", "AFFE37"));
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext();
TestPropertyValues.of("foo: {cipher}bar").applyTo(context);
this.listener.initialize(context);
assertEquals("bar", context.getEnvironment().getProperty("foo"));
}
開發者ID:spring-cloud,項目名稱:spring-cloud-commons,代碼行數:10,代碼來源:EnvironmentDecryptApplicationInitializerTests.java
示例9: errorOnDecryptWithEmpty
import org.springframework.security.crypto.encrypt.Encryptors; //導入依賴的package包/類
@Test
public void errorOnDecryptWithEmpty() {
this.listener = new EnvironmentDecryptApplicationInitializer(
Encryptors.text("deadbeef", "AFFE37"));
this.listener.setFailOnError(false);
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext();
TestPropertyValues.of("foo: {cipher}bar").applyTo(context);
this.listener.initialize(context);
// Empty is safest fallback for undecryptable cipher
assertEquals("", context.getEnvironment().getProperty("foo"));
}
開發者ID:spring-cloud,項目名稱:spring-cloud-commons,代碼行數:12,代碼來源:EnvironmentDecryptApplicationInitializerTests.java
示例10: decrypt
import org.springframework.security.crypto.encrypt.Encryptors; //導入依賴的package包/類
/**
* Decrypt the cipher with AES.
*
* @param cipher The encrypted string.
* @param salt The cipher specific salt.
* @return The decrypted cipher.
*/
public static String decrypt(String cipher, String salt) {
long start = System.nanoTime();
TextEncryptor encryptor = Encryptors.text(PASSWORD, salt);
String output = encryptor.decrypt(cipher); // This will break intentionally if something goes wrong (bad characters in the password?)
long end = System.nanoTime();
LOG.finer("Decryption took: " + timeDiff(start, end));
return output;
}
示例11: getUsersConnectionRepository
import org.springframework.security.crypto.encrypt.Encryptors; //導入依賴的package包/類
/**
* Singleton data access object providing access to connections across all users.
*/
@Override
public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator connectionFactoryLocator) {
JdbcUsersConnectionRepository repository = new JdbcUsersConnectionRepository(dataSource, connectionFactoryLocator, Encryptors.noOpText());
repository.setConnectionSignUp(new SimpleConnectionSignUp());
return repository;
}
示例12: decryptMessage
import org.springframework.security.crypto.encrypt.Encryptors; //導入依賴的package包/類
/**
* Gets an encrypted message, reconstructs the encryption key and decrypts the message
* @param message The object that contains the message to be decrypted and its encryption information
* @return The Message object with the decrypted message
*/
Message decryptMessage(Message message)
{
if(message.getCryptoSalt() != null)
{
CustomBCryptPasswordEncoder encoder = new CustomBCryptPasswordEncoder();
Object credentials = Util.getCredentials();
String cryptoKeySalt = message.getCryptoKeySalt();
String cryptoKey = encoder.encode(credentials.toString(), cryptoKeySalt);
String cryptoSalt = message.getCryptoSalt();
String encryptedMessage = message.getEncryptedMessage();
String decryptedMessage = Encryptors.text(cryptoKey, cryptoSalt).decrypt(encryptedMessage);
message.setDecryptedMessage(decryptedMessage);
}
return message;
}
示例13: textEncryptor
import org.springframework.security.crypto.encrypt.Encryptors; //導入依賴的package包/類
@Bean
public TextEncryptor textEncryptor(@Value("${application.secret}") CharSequence secret) {
return Encryptors.delux(secret, secret);
}
示例14: getUsersConnectionRepository
import org.springframework.security.crypto.encrypt.Encryptors; //導入依賴的package包/類
public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator connectionFactoryLocator) {
return new SocialRedisUsersConnectionRepository(connectionFactoryLocator, Encryptors.noOpText(), socialConnectionRepository);
}
示例15: textEncryptor
import org.springframework.security.crypto.encrypt.Encryptors; //導入依賴的package包/類
private static TextEncryptor textEncryptor() {
log.debug("New instance of " + TextEncryptor.class);
return Encryptors.noOpText();
}