72
Views
18
Comments
padding error
Question
Application Type
Reactive

padding is inavalid and cannot be removed error how to fix this

while iam encrypting json using online tool while that encrypted value and key  used in outsystems to decrypt json this error getting what does meant?

2022-12-12 06-07-07
Dhivyaraj Sivam

Hi Pydisetti,

what type of online tool are you using?


Regards,

Dhivyaraj Sivam

UserImage.jpg
Pydisetti sai

while i used to encrypt string and decrypt in outystems it getting good while i tried to encrypt json and trying to decrypt getting error

tool links :  


       https://www.devglan.com/online-tools/aes-encryption-decryption 

                   https://www.javainuse.com/aesgenerator

from these two links getting that error while i decrypting json why? is it my fault

i uses aes encryption service not crypto api in outystems



2022-12-12 06-07-07
Dhivyaraj Sivam


Is the same secret key used to encrypt and decrypt?

UserImage.jpg
Pydisetti sai
2022-12-12 06-07-07
Dhivyaraj Sivam
UserImage.jpg
Pydisetti sai

padding is invalid and cannot be removed  getting for json files can u once check it 

UserImage.jpg
Pydisetti sai

where using another website it working properly can u write encryption code for this?

2022-12-12 06-07-07
Dhivyaraj Sivam

Hi Pydisetti,

I have implemented OML for encrypting and decrypting, which I believe will be useful to you.


EncryptedDecrypted_New.oml
2024-09-09 08-44-46
BHUPENDRA SINGH

hi Pydisetti,

You can use cipher mode as "CBC" in online tool https://www.devglan.com/online-tools/aes-encryption-decryption to decrypt your value, as AesOperations using this mode for encryption and decryption of data. if you just want to test online.

UserImage.jpg
Pydisetti sai

here intilization vector is optional while implementing code and using that it getting same error how to fix intilization vector in aes operations can u plz tell or can we write code in cbc with out using intlization vector

2024-09-09 08-44-46
BHUPENDRA SINGH

Yes, you can use it without passing initialization vector, as shown in screenshot.

UserImage.jpg
Pydisetti sai

how to write code for encryption with out using intilization vector is it mandatory in cbc right

2024-09-09 08-44-46
BHUPENDRA SINGH

You can write code for encryption without using IV ( initialization vector). the library used in extension provide the default value for IV internally.

I hope this answers your question. 

UserImage.jpg
Pydisetti sai

const crypto = require('crypto');


function encrypt(plaintext, key) {

  const cipher = crypto.createCipher('aes-256-cbc', key);

  let encrypted = cipher.update(plaintext, 'utf8', 'hex');

  encrypted += cipher.final('hex');


  return encrypted;

}


function decrypt(encryptedData, key) {

  const decipher = crypto.createDecipher('aes-256-cbc', key);

  let decrypted = decipher.update(encryptedData, 'hex', 'utf8');

  decrypted += decipher.final('utf8');


  return decrypted;

}


// Example usage

const data = {

  message: "secret message"

};


const plaintext = JSON.stringify(data);

const key = crypto.randomBytes(32).toString('hex');


const encrypted = encrypt(plaintext, key);

const decrypted = decrypt(encrypted, key);


console.log(plaintext === decrypted); 

i use this code but getting same error

plz check it

UserImage.jpg
Pydisetti sai

while decrypting getting this like in starting 

UserImage.jpg
Ummer Irshad

@Pydisetti sai Any luck?

I think that the issue is happening when the size of encrypted size increasing. For example, if you encrypt a 15 character length text using the online tool  and try to decrypt it using the extension, then it is success. But, if the encrypted text length is greater than 15, then we are getting the error related to padding.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.