1212import javax .crypto .SecretKey ;
1313
1414import org .bouncycastle .asn1 .ASN1ObjectIdentifier ;
15+ import org .bouncycastle .asn1 .oiw .OIWObjectIdentifiers ;
1516import org .bouncycastle .asn1 .pkcs .PKCSObjectIdentifiers ;
1617import org .bouncycastle .asn1 .x509 .AlgorithmIdentifier ;
1718import org .bouncycastle .cms .CMSException ;
@@ -40,7 +41,6 @@ public JceCMSContentEncryptorBuilder(ASN1ObjectIdentifier encryptionOID)
4041 public JceCMSContentEncryptorBuilder (ASN1ObjectIdentifier encryptionOID , int keySize )
4142 {
4243 this .encryptionOID = encryptionOID ;
43- this .keySize = keySize ;
4444
4545 int fixedSize = KEY_SIZE_PROVIDER .getKeySize (encryptionOID );
4646
@@ -50,13 +50,23 @@ public JceCMSContentEncryptorBuilder(ASN1ObjectIdentifier encryptionOID, int key
5050 {
5151 throw new IllegalArgumentException ("incorrect keySize for encryptionOID passed to builder." );
5252 }
53+ this .keySize = 168 ;
54+ }
55+ else if (encryptionOID .equals (OIWObjectIdentifiers .desCBC ))
56+ {
57+ if (keySize != 56 && keySize != fixedSize )
58+ {
59+ throw new IllegalArgumentException ("incorrect keySize for encryptionOID passed to builder." );
60+ }
61+ this .keySize = 56 ;
5362 }
5463 else
5564 {
5665 if (fixedSize > 0 && fixedSize != keySize )
5766 {
5867 throw new IllegalArgumentException ("incorrect keySize for encryptionOID passed to builder." );
5968 }
69+ this .keySize = keySize ;
6070 }
6171 }
6272
@@ -110,10 +120,6 @@ private class CMSOutputEncryptor
110120 }
111121 else
112122 {
113- if (encryptionOID .equals (PKCSObjectIdentifiers .des_EDE3_CBC ) && keySize == 192 )
114- {
115- keySize = 168 ;
116- }
117123 keyGen .init (keySize , random );
118124 }
119125
0 commit comments