java - Android decryption: Error while finalizing cipher -


I use the images sent between encrypted and apps using Android. The

Encryption works well, but when the file reaches the destination will not decrypt it so I copied the file to the destination application and using it decrypted successfully 3rd party software < / P>

Error I get:. Invalid blockquote exception due to "error in finalizing cipher" on CipherInputStream (CipherInputStream.java:107).

Encryption & amp; Below the decryption code:

  public static string Encrypt (string plainFile, string encryptedFile) throws IOException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException {// Here you read clear. File extStore = Environment.getExternalStorageDirectory (); FileInputStream fis = New FileInputStream (plainFile); // This stream writes encrypted text, this stream will be wrapped by // other stream. FileOutputStream fos = New FileOutputStream (Encrypted File); // length of 16 bytes SecretKeySpec SKS = new SecretKeySpec ( "MyDifficultPassw" .getBytes (), "AES"); // Create cipher cipher cipher = cipher Get Instances ("AES"); Cipher It (cipher NCRYPMODE, SCS); // Output Stream CipherOutputTream COS = Wrap new cipheroutputstream (foose, cipher); // Write Bytes is Bee; Byte [] D = new byte [8]; While ((b = fis.read (d))! = -1) {cos.write (d, 0, b); } // flush and stream closer. Cos.flush (); Cos.close (); Fis.close (); Return encrypted file; } Decrypt steady string (string plainFile, string encryptedFile) throws IOException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException {file encFile = new File (encryptedFile); FileInputStream fis = New FileInputStream (encFile); FileOutputStream fos = New FileOutputStream (plainFile); Secret Sketches = New SecretCasepec ("MyDifafalPasave" .getBytes (), "AES"); Cipher cipher = cipher Get Instances ("AES"); Cipher It (cipher DECRAPTMODOD, SCS); Cipherinputstream cis = new cipher inputstream (fis, cipher); Int b; Byte [] D = new byte [8]; While ((b = cis.read (d))! = -1) {fos.write (d, 0, b); } Fos.flush (); Fos.close (); Cis.close (); Plainfile return; }  

Any ideas? Thanks

Ronan

UPDATE: The receiving encrypted file is consistently 1 small byte which seems to be causing the original file error. The error has been triggered on the block size code line while ((b = fis.read (d))! = -1) {to decrypt function

Update: Thanks for the feedback as the ultimate solution

Ronan


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -