Skip to content

Commit 7cf6f5b

Browse files
author
gefeili
committed
Test the code of Jasypt
1 parent 0957887 commit 7cf6f5b

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

prov/src/main/java/org/bouncycastle/jcajce/provider/symmetric/util/BaseBlockCipher.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ else if (modeName.startsWith("PGPCFB"))
448448
{
449449
throw new NoSuchAlgorithmException("no mode support for " + modeName);
450450
}
451-
451+
452452
ivLength = baseEngine.getBlockSize();
453453
cipher = new BufferedGenericBlockCipher(
454454
new PGPCFBBlockCipher(baseEngine, inlineIV));
@@ -634,7 +634,7 @@ else if (paddingName.equals("TBCPADDING"))
634634
protected void engineInit(
635635
int opmode,
636636
Key key,
637-
AlgorithmParameterSpec params,
637+
AlgorithmParameterSpec params,
638638
SecureRandom random)
639639
throws InvalidKeyException, InvalidAlgorithmParameterException
640640
{
@@ -825,6 +825,10 @@ else if (!(key instanceof RepeatedSecretKeySpec))
825825
// if (params instanceof PBEParameterSpec)
826826
// {
827827
// params = ((PBEParameterSpec)params).getParameterSpec();
828+
// if (((IvParameterSpec)params).getIV().length == 0)
829+
// {
830+
// params = new IvParameterSpec(((ParametersWithIV)param).getIV());
831+
// }
828832
// }
829833
// else
830834
// {

prov/src/test/java/org/bouncycastle/jcajce/provider/test/jasypt/TestJasypt.java

+9
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,14 @@ public static void main(String[] args)
1414

1515
String encryptedText = stringEncryptor.encrypt("plainText");
1616

17+
StandardPBEStringEncryptor stringdecryptor = new StandardPBEStringEncryptor();
18+
stringdecryptor.setAlgorithm("PBEWITHSHA256AND256BITAES-CBC-BC");
19+
stringdecryptor.setPassword("secretPassword");
20+
stringdecryptor.setIvGenerator(new RandomIvGenerator());
21+
stringdecryptor.setProvider(new BouncyCastleProvider());
22+
23+
String decryptedText = stringdecryptor.decrypt(encryptedText);
24+
System.out.println(decryptedText);
25+
1726
}
1827
}

0 commit comments

Comments
 (0)