मैं जावा में एक फ़ाइल को डिक्रिप्ट करने का प्रयास कर रहा हूं जिसे रिजेंडेल/सीबीसी/पीकेसीएस 7 का उपयोग करके सी # में एन्क्रिप्ट किया गया था। मैं निम्न अपवाद बार आ रही है:BadPaddingException: पैड ब्लॉक दूषित
javax.crypto.BadPaddingException: पैड ब्लॉक भ्रष्ट
org.bouncycastle.jce.provider.JCEBlockCipher.engineDoFinal (अज्ञात स्रोत)
javax.crypto.Cipher.doFinal पर पर (DashoA13 * ..)
AESFileDecrypter.decrypt (AESFileDecrypter.java:57) पर
जब doFinal(inpbytes)
विधि पहले बाइट [] के लिए वेब सर्वर द्वारा कहा जाता है। मुझे लगता है कि यह कुंजी या चतुर्थ के साथ एक समस्या है। मेरे पास परीक्षण के लिए मेरे फाइल सिस्टम पर एन्क्रिप्टेड फाइलें हैं I क्या कोई ऐसा कुछ है जो नीचे दिए गए मेरे कोड के साथ कोई भी ग़लत रूप से गलत देख सकता है?
*** keyStr बेस 64 इनकोडिंग
public AESFileDecrypter(String keyStr){
try {
Security.addProvider(new BouncyCastleProvider());
convertIvParameter();
key = new sun.misc.BASE64Decoder().decodeBuffer(keyStr);
//use the passed in Base64 decoded key to create a key object
decryptKey = new SecretKeySpec(key, "AES");
//specify the encryption algorithm
decryptCipher = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC");
//make a parameter object for the initialization vector(IV)
IvParameterSpec ivs = new IvParameterSpec(_defaultIv);
//initialize the decrypter to the correct mode, key used and IV
decryptCipher.init(Cipher.DECRYPT_MODE, decryptKey, ivs);
}
catch (Exception e) {
e.printStackTrace();
}
}
public void convertIvParameter() {
int[] iv = new int[] {11, 190, 165, 33, 68, 88, 11, 200, 245, 35, 68, 23, 60, 24, 223, 67};
_defaultIv = new byte[16];
for(int x = 0; x < _defaultIv.length; x++) {
_defaultIv[x] = (byte)iv[x];
}
}
public void decryptUpdate(byte[] inpBytes) throws Exception {
//decrypt the byte passed in from the web server
decryptCipher.update(inpBytes);
}
public byte[] decryptFinal() throws Exception {
//decrypt the byte passed in from the web server
return decryptCipher.doFinal();
}
//sends bytes to the client for diaply
private void sendBytes(FileInputStream fis, OutputStream os)throws Exception {
//set the buffer size to send 4k segments of data
aesFileDecrypter = new AESFileDecrypter(<Insert Key string here>);
byte[] buffer = new byte[4096];
int bytes = 0, totalBytes = fis.available();
//while there is still data to be sent keep looping and write the data
//to the output stream as the buffer is filled
try {
while ((bytes = fis.read(buffer)) != -1) {
aesFileDecrypter.decryptUpdate(buffer);
//os.write(buffer, 0, bytes);
}
os.write(aesFileDecrypter.decryptFinal(), 0, totalBytes);
}
catch(Exception e) {
e.printStackTrace();
}
}
उत्तर के लिए धन्यवाद। एईएस 256-बिट के लिए है, और सी # में सिफर डेटा के 4k भाग का उपयोग कर रहा है। कतर में मैं हर बार उसी आकार का उपयोग कर रहा हूं जिसे मैं कॉल करता हूं() –