java jasypt_java – 使用jasypt加密解密

博客介绍了使用Jasypt进行密码加密和解密的Java代码示例,包括使用StrongPasswordEncryptor加密密码,再用StrongTextEncryptor解密。同时指出使用Jasypt解密密码时控制台会显示错误,给出了错误信息及可能原因。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

如何使用jasypt解密加密的密码.

package com.uk.mysqlmaven.jsf.test;

import org.jasypt.util.password.StrongPasswordEncryptor;

import org.jasypt.util.text.StrongTextEncryptor;

public class PasswordEncryptionDecryptionUsingJASYPT {

public static void main(String[] args) {

try {

String password = "password";

StrongPasswordEncryptor encryptor = new StrongPasswordEncryptor();

String encryptedPassword = encryptor.encryptPassword(password);

if (encryptor.checkPassword(password, encryptedPassword)) {

//correct

System.out.println("Encrypted: "+ encryptedPassword);

} else {

//bad again

System.out.println("Error: ");

}

StrongTextEncryptor textEncryptor = new StrongTextEncryptor();

textEncryptor.setPassword(encryptedPassword);

String decryptedPassword = textEncryptor.decrypt(encryptedPassword);

System.out.println("Decrypted: "+ decryptedPassword);

} catch (Exception e) {

e.printStackTrace();

}

}

}

使用jasypt解密密码时,控制台中会显示错误.

Encrypted: JIOYXNa1+3+QefY2S7sas7LmhyOuDQcG8TTsQoTkqj0OtobCvwAFHXxoTr7z6HuP

org.jasypt.exceptions.EncryptionOperationNotPossibleException: Encryption raised an exception. A possible cause is you are using strong encryption algorithms and you have not installed the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files in this Java Virtual Machine

at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.handleInvalidKeyException(StandardPBEByteEncryptor.java:999)

at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.decrypt(StandardPBEByteEncryptor.java:976)

at org.jasypt.encryption.pbe.StandardPBEStringEncryptor.decrypt(StandardPBEStringEncryptor.java:725)

at org.jasypt.util.text.StrongTextEncryptor.decrypt(StrongTextEncryptor.java:118)

at com.uk.mysqlmaven.jsf.test.PasswordEncryptionDecryptionUsingJASYPT.main(PasswordEncryptionDecryptionUsingJASYPT.java:22)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值