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


Java StandardPBEStringEncryptor.encrypt方法代码示例

本文整理汇总了Java中org.jasypt.encryption.pbe.StandardPBEStringEncryptor.encrypt方法的典型用法代码示例。如果您正苦于以下问题:Java StandardPBEStringEncryptor.encrypt方法的具体用法?Java StandardPBEStringEncryptor.encrypt怎么用?Java StandardPBEStringEncryptor.encrypt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jasypt.encryption.pbe.StandardPBEStringEncryptor的用法示例。


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

示例1: createFakeToken

import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; //导入方法依赖的package包/类
public static String createFakeToken(String password, long validity,  Map<String, String> properties){
    try {
        StandardPBEStringEncryptor textEncryptor = new StandardPBEStringEncryptor();
        textEncryptor.setPassword(password);

        SimpleToken token = SimpleToken.of(validity, properties);

        String result = GeneralUtils.toJsonString(token);
        String encryptedResult = textEncryptor.encrypt(result);

        return encryptedResult;
    }
    catch(Exception ex){
        throw new RuntimeException(ex);
    }
}
 
开发者ID:drinkwater-io,项目名称:drinkwater-java,代码行数:17,代码来源:SimpleToken.java

示例2: initializeNewEngine

import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; //导入方法依赖的package包/类
/**
 * Initialize engine for first time use. This method created a new random data encryption passphrase which is shown
 * to no one.
 */
private void initializeNewEngine() {
	// Generate a new data passphrase
	String newDataPassphrase = generateNewDataPassphrase();
	// Encrypt the data passphrase with the key passphrase
	final StandardPBEStringEncryptor dataPassEncryptor = new StandardPBEStringEncryptor();
	dataPassEncryptor.setProviderName(CryptoConstants.BOUNCY_CASTLE_PROVIDER_NAME);
	dataPassEncryptor.setAlgorithm(CryptoConstants.STRONG_ALGO);
	dataPassEncryptor.setPassword(getKeyPassphrase());
	String encryptedNewDataPassphrase = dataPassEncryptor.encrypt(newDataPassphrase);

	// Persist the new engine config
	try {
		MutableRepositoryItem newCryptoEngineItem = getCryptoRepository().createItem(getCryptoEngineIdentifier(),
				CryptoConstants.CRYPTO_ENGINE_ITEM_DESC);
		newCryptoEngineItem.setPropertyValue(CryptoConstants.DESCRIPTION_PROP_NAME, getCryptoEngineDescription());
		newCryptoEngineItem.setPropertyValue(CryptoConstants.ENC_DATA_KEY_PROP_NAME, encryptedNewDataPassphrase);
		newCryptoEngineItem.setPropertyValue(CryptoConstants.KEY_DATE_PROP_NAME, new Date());
		getCryptoRepository().addItem(newCryptoEngineItem);
	} catch (RepositoryException e) {
		if (isLoggingError()) {
			logError("CryptoEngine.initializeEngine: " + "unable to create new crypto engine config item.", e);
		}
	}
}
 
开发者ID:sparkred-insight,项目名称:ATGCrypto,代码行数:29,代码来源:CryptoEngine.java

示例3: testEncrypt

import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; //导入方法依赖的package包/类
@Test
public void testEncrypt()
{
    StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
    encryptor.setProvider(new BouncyCastleProvider());
    encryptor.setAlgorithm("PBEWITHSHA256AND256BITAES-CBC-BC");
    encryptor.setPassword("[email protected][email protected]");
    encryptor.setKeyObtentionIterations(1000);

    String clearText = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
    System.out.println("clearText.length="+clearText.length());
    System.out.println("clearText="+clearText);
    String encryptedText = encryptor.encrypt(clearText);
    System.out.println("encryptedText.length="+encryptedText.length());
    System.out.println("encryptedText="+encryptedText);
    assertEquals(encryptedText.length(), 172);
    String decryptedText = encryptor.decrypt(encryptedText);
    assertEquals(decryptedText, clearText);
}
 
开发者ID:alfameCom,项目名称:salasanasiilo,代码行数:20,代码来源:JasyptBCAESEncryptionTest.java

示例4: generateToken

import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; //导入方法依赖的package包/类
/**
 * Generate and store an auth token.
 * @param username User to generate auth token for
 * @return the token or null if unable to store token
 */
public static String generateToken(String username) {
    String token = UUID.randomUUID().toString().toUpperCase() + "#" + username + "#" + System.nanoTime();
    StandardPBEStringEncryptor jasypt = new StandardPBEStringEncryptor();
    jasypt.setPassword(System.getenv("ENCRYPTION_PASSWORD"));
    String enToken;
    try {
        enToken = jasypt.encrypt(token);
    } catch (Exception e) {
        return null;
    }
    if (!storeToken(username, enToken)) {
        return null;
    }
    return enToken;
}
 
开发者ID:TheLoons,项目名称:SportIM-service,代码行数:21,代码来源:AuthenticationUtil.java

示例5: standardPBEStringEncryptor

import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; //导入方法依赖的package包/类
@Test
public void standardPBEStringEncryptor() {
    for (String algorithm : PBEAlgorithms) {
        if (log.isDebugEnabled())
            log.debug("StandardPBEStringEncryptor Algorithm = [{}]", algorithm);

        try {
            StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
            encryptor.setPassword("debop");
            encryptor.setAlgorithm(algorithm);

            String encryptedText = encryptor.encrypt(PLAIN_TEXT);
            String decryptedText = encryptor.decrypt(encryptedText);

            Assert.assertEquals(PLAIN_TEXT, decryptedText);
        } catch (Exception e) {
            log.error(algorithm + "은 지원하지 않습니다.", e);
        }
    }
}
 
开发者ID:debop,项目名称:debop4j,代码行数:21,代码来源:JasyptTest.java

示例6: main

import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; //导入方法依赖的package包/类
public static void main(String[] args) {
  StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
  EnvironmentStringPBEConfig config = new EnvironmentStringPBEConfig();
  config.setAlgorithm("PBEWithMD5AndDES");
  config.setPassword("root");
  encryptor.setConfig(config);
  String plainText = "admin123456";
  String ciphertext = encryptor.encrypt(plainText);
  System.out.println(plainText + ": " + ciphertext);

  System.out.println(encryptor.decrypt("fV9ZYcOCSSwxnzgvEmoP0OXO9aH17EKV"));
}
 
开发者ID:nickevin,项目名称:Qihua,代码行数:13,代码来源:TestJasypt.java

示例7: encrypt

import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; //导入方法依赖的package包/类
@Override
public String encrypt(final String plainText) {
    final StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
    encryptor.setPassword(SECURE_STRING);
    encryptor.setAlgorithm(SECURE_ALGORITHM);

    String result = plainText;
    try {
        result = encryptor.encrypt(plainText);
    } catch (EncryptionOperationNotPossibleException e) {
        log.error("Unable to encrypt",
                  e);
    }
    return result;
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:16,代码来源:DefaultPasswordServiceImpl.java

示例8: encryptToHexadecimalString

import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; //导入方法依赖的package包/类
/**
 * Encrypt a Message Text to a Hexadecimal String usable for a WEB Url.
 *
 * @param message to be encrypted
 * @return String of a Encrypted Hexadecimal String
 */
public static String encryptToHexadecimalString(String message) {
    initializeDefaultCryptographyProvider();
    StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
    encryptor.setPassword(SALT_PW);
    encryptor.setAlgorithm(BC_ALGORITHM_NAME_PBE_MD5_TRIPLE_DES);
    encryptor.setKeyObtentionIterations(KEY_OBTENTION_ITERATIONS);
    encryptor.setStringOutputType(STRING_OUTPUT_TYPE_HEXADECIMAL);
    return encryptor.encrypt(message);
}
 
开发者ID:jaschenk,项目名称:jeffaschenk-commons,代码行数:16,代码来源:SecurityServiceProviderUtility.java

示例9: setUp

import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception
{
  MrGeoProperties.resetProperties();

  StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
  encryptor.setPassword(TEST_MASTER_PASSWORD);
  encryptedValue = "ENC(" + encryptor.encrypt(decryptedValue) + ")";

}
 
开发者ID:ngageoint,项目名称:mrgeo,代码行数:11,代码来源:MrGeoPropertiesTest.java

示例10: encrypt

import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; //导入方法依赖的package包/类
private static String encrypt(String string, String key){
    StandardPBEStringEncryptor encryptor = getEncryptor(key);
    String encrypted = encryptor.encrypt(string);
    return Base64.encode(encrypted);
}
 
开发者ID:williamwebb,项目名称:divide,代码行数:6,代码来源:AuthTokenUtils.java


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