本文整理匯總了Java中org.springframework.security.crypto.encrypt.Encryptors.text方法的典型用法代碼示例。如果您正苦於以下問題:Java Encryptors.text方法的具體用法?Java Encryptors.text怎麽用?Java Encryptors.text使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.security.crypto.encrypt.Encryptors
的用法示例。
在下文中一共展示了Encryptors.text方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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);
}
}
}
示例2: 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);
}
}
}
示例3: 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
示例4: 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
示例5: 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;
}
示例6: encrypt
import org.springframework.security.crypto.encrypt.Encryptors; //導入方法依賴的package包/類
/**
* Encrypt the input with AES.
*
* @param input The string to be encrypted.
* @param salt The input specific salt.
* @return The encrypted string - SHA256 with 1024 iterations.
*/
public static String encrypt(String input, String salt) {
long start = System.nanoTime();
TextEncryptor encryptor = Encryptors.text(PASSWORD, salt);
String cipher = encryptor.encrypt(input); // This will break intentionally if something goes wrong (bad characters in the password?)
long end = System.nanoTime();
LOG.finer("Encryption took: " + timeDiff(start, end));
return cipher;
}
示例7: shouldEncryptUsingApplicationAndProfiles
import org.springframework.security.crypto.encrypt.Encryptors; //導入方法依賴的package包/類
@Test
public void shouldEncryptUsingApplicationAndProfiles() {
this.controller = new EncryptionController(
new SingleTextEncryptorLocator(Encryptors.text("application", "11")));
// when
String encrypted = this.controller.encrypt(this.application, this.profiles,
this.data, TEXT_PLAIN);
// then
assertEquals(this.data, this.controller.decrypt(this.application, this.profiles,
encrypted, TEXT_PLAIN));
}
開發者ID:spring-cloud,項目名稱:spring-cloud-config,代碼行數:15,代碼來源:EncryptionControllerMultiTextEncryptorTests.java
示例8: encryptCredentials
import org.springframework.security.crypto.encrypt.Encryptors; //導入方法依賴的package包/類
public EncryptedCredentials encryptCredentials(Credentials credentials) {
String salt = KeyGenerators.string().generateKey();
TextEncryptor enc = Encryptors.text(secret, salt);
return new EncryptedCredentials(enc.encrypt(credentials.toString()), salt);
}
示例9: decryptCredentials
import org.springframework.security.crypto.encrypt.Encryptors; //導入方法依賴的package包/類
public Credentials decryptCredentials(EncryptedCredentials encCred) {
TextEncryptor enc = Encryptors.text(secret, encCred.getSalt());
String[] decrypted = enc.decrypt(encCred.getEncryptedCredentials()).split(":");
return new Credentials(decrypted[0], decrypted[1]);
}
示例10: getTextEncryptor
import org.springframework.security.crypto.encrypt.Encryptors; //導入方法依賴的package包/類
@Bean
public TextEncryptor getTextEncryptor() {
return Encryptors.text(encryptKey, "deadbeef");
}
示例11: SpringEncryptor
import org.springframework.security.crypto.encrypt.Encryptors; //導入方法依賴的package包/類
/**
* Creates a new SpringEncryptor object.
*
* @param password JAVADOC.
*/
public SpringEncryptor(String password) {
this.encryptor = Encryptors.text(password, SALT);
}