当前位置: 首页>>代码示例>>Java>>正文


Java TextEncryptor类代码示例

本文整理汇总了Java中org.springframework.security.crypto.encrypt.TextEncryptor的典型用法代码示例。如果您正苦于以下问题:Java TextEncryptor类的具体用法?Java TextEncryptor怎么用?Java TextEncryptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TextEncryptor类属于org.springframework.security.crypto.encrypt包,在下文中一共展示了TextEncryptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: KvMapperFactory

import org.springframework.security.crypto.encrypt.TextEncryptor; //导入依赖的package包/类
@Autowired
@SuppressWarnings("unchecked")
public KvMapperFactory(ObjectMapper objectMapper, KeyValueStorage storage, TextEncryptor encryptor, Validator validator) {
    this.objectMapper = objectMapper;
    this.storage = storage;
    this.validator = validator;

    ImmutableMap.Builder<Class<?>, FieldSetter> builder = ImmutableMap.builder();
    builder.put(Map.class, (field, value) -> {
        Map fieldMap = (Map) field;
        fieldMap.clear();
        if (value != null) {
            fieldMap.putAll((Map)value);
        }
    });
    builder.put(Collection.class, (field, value) -> {
        Collection fieldColl = (Collection) field;
        fieldColl.clear();
        fieldColl.addAll((Collection)value);
    });
    setters = builder.build();
    interceptors = ImmutableMap.<Class<?>, PropertyInterceptor>builder()
      .put(PropertyCipher.class, new PropertyCipher(encryptor))
      .build();
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:26,代码来源:KvMapperFactory.java

示例2: textEncryptor

import org.springframework.security.crypto.encrypt.TextEncryptor; //导入依赖的package包/类
@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.key.getRsa().getAlgorithm(), this.key.getRsa().getSalt(),
					this.key.getRsa().isStrong());
		}

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

	return new EncryptorFactory().create(this.key.getKey());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-commons,代码行数:21,代码来源:EncryptionBootstrapConfiguration.java

示例3: decrypt

import org.springframework.security.crypto.encrypt.TextEncryptor; //导入依赖的package包/类
@RequestMapping(value = "/decrypt/{name}/{profiles}", method = RequestMethod.POST)
public String decrypt(@PathVariable String name, @PathVariable String profiles,
		@RequestBody String data, @RequestHeader("Content-Type") MediaType type) {
	checkEncryptorInstalled(name, profiles);
	try {
		String input = stripFormData(this.helper.stripPrefix(data), type, true);
		Map<String, String> encryptorKeys = this.helper.getEncryptorKeys(name,
				profiles, data);
		TextEncryptor encryptor = this.encryptor.locate(encryptorKeys);
		String decrypted = encryptor.decrypt(input);
		logger.info("Decrypted cipher data");
		return decrypted;
	}
	catch (IllegalArgumentException|IllegalStateException e) {
		logger.error("Cannot decrypt key:" + name + ", value:" + data, e);
		throw new InvalidCipherException();
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-config,代码行数:19,代码来源:EncryptionController.java

示例4: addEnvironment

import org.springframework.security.crypto.encrypt.TextEncryptor; //导入依赖的package包/类
@Test
public void addEnvironment() {
	TextEncryptorLocator locator = new TextEncryptorLocator() {

		private RsaSecretEncryptor encryptor = new RsaSecretEncryptor();

		@Override
		public TextEncryptor locate(Map<String, String> keys) {
			return this.encryptor;
		}
	};
	this.controller = new EncryptionController(locator);
	// Add space to input
	String cipher = this.controller.encrypt("app", "default", "foo bar",
			MediaType.TEXT_PLAIN);
	assertFalse("Wrong cipher: " + cipher, cipher.contains("{name:app}"));
	String decrypt = this.controller.decrypt("app", "default", cipher,
			MediaType.TEXT_PLAIN);
	assertEquals("Wrong decrypted plaintext: " + decrypt, "foo bar", decrypt);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-config,代码行数:21,代码来源:EncryptionControllerTests.java

示例5: RedisConnectionRepository

import org.springframework.security.crypto.encrypt.TextEncryptor; //导入依赖的package包/类
public RedisConnectionRepository(final ConnectionFactoryLocator connectionFactoryLocator, final TextEncryptor textEncryptor, final SocialRedisConnectionRepository socialRedisConnectionRepository, final String userId) {
    Assert.notNull(socialRedisConnectionRepository, "socialRedisConnectionRepository is required");
    Assert.notNull(userId, "userId is required");

    this.userId = userId;
    this.socialRedisConnectionRepository = socialRedisConnectionRepository;
    this.connectionFactoryLocator = connectionFactoryLocator;
    this.textEncryptor = textEncryptor;
}
 
开发者ID:Turbots,项目名称:SpringOne2016,代码行数:10,代码来源:RedisConnectionRepository.java

示例6: RedisUsersConnectionRepository

import org.springframework.security.crypto.encrypt.TextEncryptor; //导入依赖的package包/类
public RedisUsersConnectionRepository(ConnectionFactoryLocator connectionFactoryLocator, TextEncryptor textEncryptor, SocialRedisConnectionRepository socialRedisConnectionRepository) {
    Assert.notNull(connectionFactoryLocator);
    Assert.notNull(textEncryptor);
    Assert.notNull(socialRedisConnectionRepository);

    this.connectionFactoryLocator = connectionFactoryLocator;
    this.textEncryptor = textEncryptor;
    this.socialRedisConnectionRepository = socialRedisConnectionRepository;
}
 
开发者ID:Turbots,项目名称:SpringOne2016,代码行数:10,代码来源:RedisUsersConnectionRepository.java

示例7: textEncryptor

import org.springframework.security.crypto.encrypt.TextEncryptor; //导入依赖的package包/类
@Bean
TextEncryptor textEncryptor(@Value("${dm.security.cipher.password}") String password,
                            @Value("${dm.security.cipher.salt}") String salt) {
    // on wrong configuration system will pass prop expressions '${prop}' as value, we need to detect this
    Assert.isTrue(StringUtils.hasText(password) && !password.startsWith("${"), "'dm.security.cipher.password' is invalid.");
    Assert.isTrue(StringUtils.hasText(salt) && !salt.startsWith("${"), "'dm.security.cipher.salt' is invalid.");
    //we use bouncycastle because standard  java does not support keys bigger 128bits
    // but spring also does not provide any way to change key size
    // see also: https://github.com/spring-projects/spring-security/issues/2917
    BytesEncryptor encryptor = new BouncyCastleAesGcmBytesEncryptor(password, salt);
    return new Base64Encryptor(encryptor);
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:13,代码来源:SecurityConfiguration.java

示例8: encrypt

import org.springframework.security.crypto.encrypt.TextEncryptor; //导入依赖的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

示例9: decrypt

import org.springframework.security.crypto.encrypt.TextEncryptor; //导入依赖的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

示例10: textEncryptor

import org.springframework.security.crypto.encrypt.TextEncryptor; //导入依赖的package包/类
@Bean
TextEncryptor textEncryptor() {
    return new TextEncryptor() {
        @Override
        public String encrypt(String text) { return text; }

        @Override
        public String decrypt(String encryptedText) { return encryptedText; }
    };
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:11,代码来源:MailServiceTest.java

示例11: symmetric

import org.springframework.security.crypto.encrypt.TextEncryptor; //导入依赖的package包/类
@Test
public void symmetric() {
	ConfigurableApplicationContext context = new SpringApplicationBuilder(
			EncryptionBootstrapConfiguration.class).web(WebApplicationType.NONE)
					.properties("encrypt.key:pie").run();
	TextEncryptor encryptor = context.getBean(TextEncryptor.class);
	assertEquals("foo", encryptor.decrypt(encryptor.encrypt("foo")));
	context.close();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-commons,代码行数:10,代码来源:EncryptionBootstrapConfigurationTests.java

示例12: rsaKeyStore

import org.springframework.security.crypto.encrypt.TextEncryptor; //导入依赖的package包/类
@Test
public void rsaKeyStore() {
	ConfigurableApplicationContext context = new SpringApplicationBuilder(
			EncryptionBootstrapConfiguration.class)
					.web(WebApplicationType.NONE)
					.properties("encrypt.keyStore.location:classpath:/server.jks",
							"encrypt.keyStore.password:letmein",
							"encrypt.keyStore.alias:mytestkey",
							"encrypt.keyStore.secret:changeme")
					.run();
	TextEncryptor encryptor = context.getBean(TextEncryptor.class);
	assertEquals("foo", encryptor.decrypt(encryptor.encrypt("foo")));
	context.close();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-commons,代码行数:15,代码来源:EncryptionBootstrapConfigurationTests.java

示例13: rsaKeyStoreWithRelaxedProperties

import org.springframework.security.crypto.encrypt.TextEncryptor; //导入依赖的package包/类
@Test
public void rsaKeyStoreWithRelaxedProperties() {
	ConfigurableApplicationContext context = new SpringApplicationBuilder(
			EncryptionBootstrapConfiguration.class)
					.web(WebApplicationType.NONE)
					.properties("encrypt.key-store.location:classpath:/server.jks",
							"encrypt.key-store.password:letmein",
							"encrypt.key-store.alias:mytestkey",
							"encrypt.key-store.secret:changeme")
					.run();
	TextEncryptor encryptor = context.getBean(TextEncryptor.class);
	assertEquals("foo", encryptor.decrypt(encryptor.encrypt("foo")));
	context.close();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-commons,代码行数:15,代码来源:EncryptionBootstrapConfigurationTests.java

示例14: testWithRsaPrivateKey

import org.springframework.security.crypto.encrypt.TextEncryptor; //导入依赖的package包/类
@Test
public void testWithRsaPrivateKey() throws Exception {
	String key = StreamUtils.copyToString(
			new ClassPathResource("/example-test-rsa-private-key").getInputStream(),
			Charset.forName("ASCII"));
	//RSA private key needs to be with no new lines 
	//-----BEGIN RSA PRIVATE KEY-----MIIEowI....iX8htsO-----END RSA PRIVATE KEY-----
	String keyNoNewLines = key.replaceAll("\\n", "");
	TextEncryptor encryptor = new EncryptorFactory().create(keyNoNewLines);
	String toEncrypt = "sample text to encrypt";
	String encrypted = encryptor.encrypt(toEncrypt);

	assertEquals(toEncrypt, encryptor.decrypt(encrypted));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-commons,代码行数:15,代码来源:EncryptorFactoryTests.java

示例15: decrypt

import org.springframework.security.crypto.encrypt.TextEncryptor; //导入依赖的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


注:本文中的org.springframework.security.crypto.encrypt.TextEncryptor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。