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


Java Encryptors类代码示例

本文整理汇总了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;
}
 
开发者ID:arturhgca,项目名称:message-crypto,代码行数:21,代码来源:MessageController.java

示例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()
    );
}
 
开发者ID:eduyayo,项目名称:gamesboard,代码行数:14,代码来源:SocialContext.java

示例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);
        }
    }
}
 
开发者ID:bulktrade,项目名称:SMSC,代码行数:18,代码来源:EncrypterUtil.java

示例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);
        }
    }
}
 
开发者ID:bulktrade,项目名称:SMSC,代码行数:18,代码来源:EncrypterUtil.java

示例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;
}
 
开发者ID:music-for-all,项目名称:music-for-all-application,代码行数:9,代码来源:SocialConfig.java

示例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;
}
 
开发者ID:gill3s,项目名称:opentipbot,代码行数:10,代码来源:SocialContext.java

示例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;
}
 
开发者ID:xeraa,项目名称:morphia-demo,代码行数:16,代码来源:AESEncryptor.java

示例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;
}
 
开发者ID:yarli4u,项目名称:spring-social-meetup,代码行数:10,代码来源:SocialConfig.java

示例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;
}
 
开发者ID:arturhgca,项目名称:message-crypto,代码行数:21,代码来源:MessageController.java

示例13: textEncryptor

import org.springframework.security.crypto.encrypt.Encryptors; //导入依赖的package包/类
@Bean
public TextEncryptor textEncryptor(@Value("${application.secret}") CharSequence secret) {
    return Encryptors.delux(secret, secret);
}
 
开发者ID:leon,项目名称:spring-oauth-social-microservice-starter,代码行数:5,代码来源:SecurityConfig.java

示例14: getUsersConnectionRepository

import org.springframework.security.crypto.encrypt.Encryptors; //导入依赖的package包/类
public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator connectionFactoryLocator) {
    return new SocialRedisUsersConnectionRepository(connectionFactoryLocator, Encryptors.noOpText(), socialConnectionRepository);
}
 
开发者ID:Turbots,项目名称:social-redis-spring-boot-starter,代码行数:4,代码来源:SocialRedisConfigurer.java

示例15: textEncryptor

import org.springframework.security.crypto.encrypt.Encryptors; //导入依赖的package包/类
private static TextEncryptor textEncryptor() {
    log.debug("New instance of " + TextEncryptor.class);
    return Encryptors.noOpText();
}
 
开发者ID:esutoniagodesu,项目名称:egd-web,代码行数:5,代码来源:SocialConfig.java


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