This website supplies cookies indigenous Google to supply its services and to analyze traffic. Click right here to learn more.


You are watching: Javax crypto badpaddingexception given final block not properly padded

Auto-suggest helps you easily narrow under your search outcomes by suggesting possible matches together you type.
*

package com.tmobile;import com.apigee.flow.execution.ExecutionContext;import com.apigee.flow.execution.ExecutionResult;import com.apigee.flow.execution.spi.Execution;import com.apigee.flow.message.MessageContext;import java.util.Arrays;import javax.crypto.BadPaddingException;import javax.crypto.Cipher;import javax.crypto.IllegalBlockSizeException;import javax.crypto.SecretKey;import javax.crypto.spec.SecretKeySpec;import javax.xml.bind.DatatypeConverter;public class DecryptionDocumentId2 implements Execution private static final String _varPrefix = "decrypt_"; private static last String varName(String s) return _varPrefix + s;


See more: Dr Seuss Pumpkin As Your Favorite Dr, Latest News

Override publicly ExecutionResult execute(MessageContext messageContext, ExecutionContext executionContext) try // decode the base64 encoded string String decryptionKey1 = messageContext.getVariable("dk1_decryption"); //String decryptionKey2 = messageContext.getVariable("dk2_decryption"); byte<> key1 = decryptionKey1.getBytes("UTF-8"); //byte<> key2 = decryptionKey2.getBytes("UTF-8"); SecretKey secretKey1 = new SecretKeySpec(key1, 0, key1.length, "AES"); // SecretKey secretKey2 = brand-new SecretKeySpec(key2, 0, key2.length, "AES"); cable documentId = messageContext.getVariable("documentId"); if (documentId == null) messageContext.setVariable(varName("reason"), "missing documentId"); return ExecutionResult.ABORT; string decryptedValue = decrypt(documentId.trim(),secretKey1,messageContext); messageContext.setVariable("decryptedMsisdn", decryptedValue); return ExecutionResult.SUCCESS; record (Exception e) wire error = e.toString(); messageContext.setVariable(varName("error"), error); int ch = error.lastIndexOf(":"); if (ch >= 0) messageContext.setVariable(varName("reason"), error.substring(ch+2)); else messageContext.setVariable(varName("reason"), error); return ExecutionResult.ABORT; exclusive String decrypt(String encryptedText, SecretKey secretKey, MessageContext messageContext) throws exemption Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, secretKey); byte<> decryptedTextBytes = null; shot decryptedTextBytes = cipher.doFinal(DatatypeConverter.parseBase64Binary(encryptedText)); catch (IllegalBlockSizeException e) messageContext.setVariable(varName("reason1"), e.toString()); litter e; capture (BadPaddingException e) messageContext.setVariable(varName("reason2"), e.toString()); throw e; return brand-new String(decryptedTextBytes); This is a java code for one Apigee sheet callout. During execution, if trying come decrypt encrypted data in APIGEE , we are getting error of last block not properly padded. The password we started with is: http://aesencryption.net/#Java-aes-encryption-example We generate encrypted data native there and also are trying to decrypt it with a key.