本文整理汇总了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);
}
}
示例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);
}
}
}
示例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);
}
示例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;
}
示例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);
}
}
}
示例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"));
}
示例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;
}
示例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);
}
示例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) + ")";
}
示例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);
}