當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。