當前位置: 首頁>>代碼示例>>Java>>正文


Java Encryptors.text方法代碼示例

本文整理匯總了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);
        }
    }
}
 
開發者ID:bulktrade,項目名稱:SMSC,代碼行數:18,代碼來源:EncrypterUtil.java

示例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);
        }
    }
}
 
開發者ID:bulktrade,項目名稱:SMSC,代碼行數:18,代碼來源:EncrypterUtil.java

示例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;
}
 
開發者ID:xeraa,項目名稱:morphia-demo,代碼行數:16,代碼來源:AESEncryptor.java

示例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;
}
 
開發者ID:xeraa,項目名稱:morphia-demo,代碼行數:16,代碼來源:AESEncryptor.java

示例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);
}
 
開發者ID:HTWK-App,項目名稱:Server-Application,代碼行數:6,代碼來源:AuthenticationService.java

示例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]);
}
 
開發者ID:HTWK-App,項目名稱:Server-Application,代碼行數:6,代碼來源:AuthenticationService.java

示例10: getTextEncryptor

import org.springframework.security.crypto.encrypt.Encryptors; //導入方法依賴的package包/類
@Bean
public TextEncryptor getTextEncryptor() {
    return Encryptors.text(encryptKey, "deadbeef");
}
 
開發者ID:syndesisio,項目名稱:syndesis,代碼行數:5,代碼來源:Application.java

示例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);
}
 
開發者ID:cucina,項目名稱:opencucina,代碼行數:9,代碼來源:SpringEncryptor.java


注:本文中的org.springframework.security.crypto.encrypt.Encryptors.text方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。