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