当前位置: 首页>>代码示例>>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;未经允许,请勿转载。