congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
BadPaddingException
Code IndexAdd Tabnine to your IDE (free)

How to use
BadPaddingException
in
javax.crypto

Best Java code snippets using javax.crypto.BadPaddingException (Showing top 20 results out of 828)

Refine searchRefine arrow

  • IllegalBlockSizeException
  • InvalidKeyException
  • Cipher
  • NoSuchAlgorithmException
  • NoSuchPaddingException
  • PKCS8EncodedKeySpec
origin: robovm/robovm

  Cipher cipher = Cipher.getInstance(algName);
  if (algParameters == null) {
    cipher.init(Cipher.DECRYPT_MODE, decryptKey);
  } else {
    cipher.init(Cipher.DECRYPT_MODE, decryptKey, algParameters);
  byte[] decryptedData = cipher.doFinal(encryptedData);
    throw invalidKey();
  return new PKCS8EncodedKeySpec(decryptedData);
} catch (NoSuchPaddingException e) {
  throw new NoSuchAlgorithmException(e.getMessage());
} catch (InvalidAlgorithmParameterException e) {
  throw new NoSuchAlgorithmException(e.getMessage());
} catch (IllegalStateException e) {
  throw new InvalidKeyException(e.getMessage());
} catch (IllegalBlockSizeException e) {
  throw new InvalidKeyException(e.getMessage());
} catch (BadPaddingException e) {
  throw new InvalidKeyException(e.getMessage());
origin: aa112901/remusic

private static byte[] decrypt(byte[] content, String password) {
  try {
    byte[] keyStr = getKey(password);
    SecretKeySpec key = new SecretKeySpec(keyStr, "AES");
    Cipher cipher = Cipher.getInstance(algorithmStr);//algorithmStr
    cipher.init(Cipher.DECRYPT_MODE, key);//   ʼ
    byte[] result = cipher.doFinal(content);
    return result; //
  } catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
  } catch (NoSuchPaddingException e) {
    e.printStackTrace();
  } catch (InvalidKeyException e) {
    e.printStackTrace();
  } catch (IllegalBlockSizeException e) {
    e.printStackTrace();
  } catch (BadPaddingException e) {
    e.printStackTrace();
  }
  return null;
}
origin: wildfly/wildfly

private byte[] pkcs7UnPad(byte[] buffer) throws BadPaddingException {
  byte last = buffer[buffer.length - 1];
  int i = buffer.length - 2;
  while (buffer[i] == last) {
    i--;
  }
  if (i + 1 + last != buffer.length) {
    throw new BadPaddingException();
  }
  return Arrays.copyOfRange(buffer, 0, i + 1);
}
origin: robovm/robovm

        NoSuchAlgorithmException, InvalidKeyException {
if (key == null) {
  throw new InvalidKeyException("key == null");
  Cipher cipher = Cipher.getInstance(sealAlg);
  if ((paramsAlg != null) && (paramsAlg.length() != 0)) {
    AlgorithmParameters params =
      AlgorithmParameters.getInstance(paramsAlg);
    params.init(encodedParams);
    cipher.init(Cipher.DECRYPT_MODE, key, params);
  } else {
    cipher.init(Cipher.DECRYPT_MODE, key);
  byte[] serialized = cipher.doFinal(encryptedContent);
  throw new NoSuchAlgorithmException(e.toString());
} catch (InvalidAlgorithmParameterException e) {
  throw new NoSuchAlgorithmException(e.toString());
} catch (IllegalBlockSizeException e) {
  throw new NoSuchAlgorithmException(e.toString());
} catch (BadPaddingException e) {
  throw new NoSuchAlgorithmException(e.toString());
} catch (IllegalStateException  e) {
origin: com.braintreepayments/encryption

public static String encrypt(byte[] data, String publicKeyString) throws BraintreeEncryptionException {
  Cipher rsa;
  try {
    rsa = Cipher.getInstance(TRANSFORMATION);
    PublicKey publicKey = publicKey(publicKeyString);
    rsa.init(Cipher.ENCRYPT_MODE, publicKey);
    byte[] encodedData = Base64.encode(data);
    byte[] encryptedData = rsa.doFinal(encodedData);
    return new String(Base64.encode(encryptedData));
  } catch (NoSuchAlgorithmException e) {
    throw new BraintreeEncryptionException("No Such Algorithm: " + e.getMessage());
  } catch (NoSuchPaddingException e) {
    throw new BraintreeEncryptionException("No Such Padding: " + e.getMessage());
  } catch (InvalidKeyException e) {
    throw new BraintreeEncryptionException("Invalid Key: " + e.getMessage());
  } catch (IllegalBlockSizeException e) {
    throw new BraintreeEncryptionException("Illegal Block Size: " + e.getMessage());
  } catch (BadPaddingException e) {
    throw new BraintreeEncryptionException("Bad Padding: " + e.getMessage());
  }
}
origin: com.madgag.spongycastle/prov

if (provider == null)
  c = Cipher.getInstance("AES/CCM/NoPadding");
  c = Cipher.getInstance("AES/CCM/NoPadding", provider);
c.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(keyBytes, "AES"));
byte[] encOut = c.doFinal(storeData.getEncoded());
throw new NoSuchAlgorithmException(e.toString());
throw new IOException(e.toString());
throw new IOException(e.toString());
throw new IOException(e.toString());
origin: aa112901/remusic

private static byte[] encrypt(byte[] content, byte[] keyBytes) {
  byte[] encryptedText = null;
  if (!isInited) {
    init();
  }
  /**
   *类 SecretKeySpec
   *可以使用此类来根据一个字节数组构造一个 SecretKey,
   *而无须通过一个(基于 provider 的)SecretKeyFactory。
   *此类仅对能表示为一个字节数组并且没有任何与之相关联的钥参数的原始密钥有用
   *构造方法根据给定的字节数组构造一个密钥。
   *此构造方法不检查给定的字节数组是否指定了一个算法的密钥。
   */
  Key key = new SecretKeySpec(keyBytes, "AES");
  try {
    // 用密钥初始化此 cipher。
    cipher.init(Cipher.ENCRYPT_MODE, key);
  } catch (InvalidKeyException e) {
    e.printStackTrace();
  }
  try {
    //按单部分操作加密或解密数据,或者结束一个多部分操作。(不知道神马意思)
    encryptedText = cipher.doFinal(content);
  } catch (IllegalBlockSizeException e) {
    e.printStackTrace();
  } catch (BadPaddingException e) {
    e.printStackTrace();
  }
  return encryptedText;
}
origin: robovm/robovm

try {
  if (cipher != null) {
    result = cipher.doFinal();
    if (result != null) {
      out.write(result);
  throw new IOException(e.getMessage());
} catch (IllegalBlockSizeException e) {
  throw new IOException(e.getMessage());
} finally {
  if (out != null) {
origin: com.braintreepayments/encryption

public static String encrypt(String data, byte[] aesKey, byte[] iv) throws BraintreeEncryptionException {
  SecretKeySpec key = new SecretKeySpec(aesKey, ALGORITHM);
  Cipher cipher = aesCipher();
  try {
    IvParameterSpec ivParamSpec = new IvParameterSpec(iv);
    cipher.init(Cipher.ENCRYPT_MODE, key, ivParamSpec);
    byte[] encryptedBytes = cipher.doFinal(data.getBytes());
    byte[] buffer = Arrays.copyOf(iv, iv.length + encryptedBytes.length);
    System.arraycopy(encryptedBytes, 0, buffer, iv.length, encryptedBytes.length);
    return new String(Base64.encode(buffer));
  } catch (InvalidKeyException e) {
    throw new BraintreeEncryptionException("Invalid Key: " + e.getMessage());
  } catch (BadPaddingException e) {
    throw new BraintreeEncryptionException("Bad Padding: " + e.getMessage());
  } catch (IllegalBlockSizeException e) {
    throw new BraintreeEncryptionException("Illegal Block Size: " + e.getMessage());
  } catch (InvalidAlgorithmParameterException e) {
    throw new BraintreeEncryptionException("Invalid Algorithm: " + e.getMessage());
  }
}
origin: robovm/robovm

  oos.writeObject(object);
  oos.flush();
  AlgorithmParameters ap = c.getParameters();
  this.encodedParams = (ap == null) ? null : ap.getEncoded();
  this.paramsAlg = (ap == null) ? null : ap.getAlgorithm();
  this.sealAlg = c.getAlgorithm();
  this.encryptedContent = c.doFinal(bos.toByteArray());
} catch (BadPaddingException e) {
  throw new IOException(e.toString());
origin: org.tmatesoft.svnkit/svnkit

private byte[] encrypt(byte[] key, byte[] bytes) throws SVNException {
  Cipher ecipher = getCipher(key);
  try {
    byte[] enc = ecipher.doFinal(bytes);
    return enc;
  } catch (IllegalBlockSizeException e) {
    SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.IO_ERROR, "Invalid block size for DES encryption: {0}", e.getLocalizedMessage());
    SVNErrorManager.error(err, SVNLogType.NETWORK);
  } catch (BadPaddingException e) {
    SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.IO_ERROR, "Data not padded correctly for DES encryption: {0}", e.getLocalizedMessage());
    SVNErrorManager.error(err, SVNLogType.NETWORK);
  }
  return null;
}

origin: robovm/robovm

  byte[] decryptedData = cipher.doFinal(encryptedData);
  try {
    ASN1PrivateKeyInfo.verify(decryptedData);
    throw new InvalidKeySpecException("Decrypted data does not represent valid PKCS#8 PrivateKeyInfo");
  return new PKCS8EncodedKeySpec(decryptedData);
} catch (IllegalStateException e) {
  throw new InvalidKeySpecException(e.getMessage());
} catch (IllegalBlockSizeException e) {
  throw new InvalidKeySpecException(e.getMessage());
} catch (BadPaddingException e) {
  throw new InvalidKeySpecException(e.getMessage());
origin: org.bouncycastle/bcprov-debug-jdk15on

  byte[] encOut = c.doFinal(storeData.getEncoded());
  AlgorithmParameters algorithmParameters = c.getParameters();
  byte[] encOut = c.doFinal(storeData.getEncoded());
  PBES2Parameters pbeParams = new PBES2Parameters(pbkdAlgId, new EncryptionScheme(NISTObjectIdentifiers.id_aes256_wrap_pad));
throw new NoSuchAlgorithmException(e.toString());
throw new IOException(e.toString());
throw new IOException(e.toString());
throw new IOException(e.toString());
origin: schwabe/ics-openvpn

@Override
public byte[] getSignedData(String alias, byte[] data) throws RemoteException {
  try {
    return SimpleSigner.signData(data);
  } catch (IOException e) {
    e.printStackTrace();
  } catch (NoSuchPaddingException e) {
    e.printStackTrace();
  } catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
  } catch (IllegalBlockSizeException e) {
    e.printStackTrace();
  } catch (BadPaddingException e) {
    e.printStackTrace();
  } catch (InvalidKeySpecException e) {
    e.printStackTrace();
  } catch (InvalidKeyException e) {
    e.printStackTrace();
  }
  // Something failed, return null
  return null;
}
origin: ibinti/bugvm

protected byte[] engineWrap(
   Key     key)
 throws IllegalBlockSizeException, InvalidKeyException
 {
   byte[] encoded = key.getEncoded();
   if (encoded == null)
   {
     throw new InvalidKeyException("Cannot wrap key, null encoding.");
   }
   try
   {
     return engineDoFinal(encoded, 0, encoded.length);
   }
   catch (BadPaddingException e)
   {
     throw new IllegalBlockSizeException(e.getMessage());
   }
 }
origin: com.madgag/scprov-jdk15on

protected int engineDoFinal(
  byte[]  input,
  int     inputOffset,
  int     inputLen,
  byte[]  output,
  int     outputOffset) 
  throws IllegalBlockSizeException, BadPaddingException
{
  int     len = 0;
  if (inputLen != 0)
  {
      len = cipher.processBytes(input, inputOffset, inputLen, output, outputOffset);
  }
  try
  {
    return (len + cipher.doFinal(output, outputOffset + len));
  }
  catch (DataLengthException e)
  {
    throw new IllegalBlockSizeException(e.getMessage());
  }
  catch (InvalidCipherTextException e)
  {
    throw new BadPaddingException(e.getMessage());
  }
}
origin: com.walmartlabs.concord.server/concord-server

public static InputStream decrypt(InputStream input, byte[] password, byte[] salt) {
  try {
    Cipher c = init(password, salt, Cipher.DECRYPT_MODE);
    return new CipherInputStream(input, c);
  } catch (BadPaddingException e) {
    throw new SecurityException("Error decrypting a secret: " + e.getMessage() + ". Invalid input data and/or a password.");
  } catch (GeneralSecurityException e) {
    throw new SecurityException("Error decrypting a secret: " + e.getMessage());
  }
}
origin: cloudant/sync-android

  throw new DPKException("Failed to encrypt DPK.  Cause: " + e.getLocalizedMessage(), e);
} catch (NoSuchPaddingException e) {
  throw new DPKException("Failed to encrypt DPK.  Cause: " + e.getLocalizedMessage(), e);
} catch (NoSuchAlgorithmException e) {
  throw new DPKException("Failed to encrypt DPK.  Cause: " + e.getLocalizedMessage(), e);
} catch (IllegalBlockSizeException e) {
  throw new DPKException("Failed to encrypt DPK.  Cause: " + e.getLocalizedMessage(), e);
} catch (BadPaddingException e) {
  throw new DPKException("Failed to encrypt DPK.  Cause: " + e.getLocalizedMessage(), e);
} catch (InvalidAlgorithmParameterException e) {
  throw new DPKException("Failed to encrypt DPK.  Cause: " + e.getLocalizedMessage(), e);
origin: robovm/robovm

  Cipher cipher = Cipher.getInstance(sealAlg, provider);
  if ((paramsAlg != null) && (paramsAlg.length() != 0)) {
    AlgorithmParameters params =
      AlgorithmParameters.getInstance(paramsAlg);
    params.init(encodedParams);
    cipher.init(Cipher.DECRYPT_MODE, key, params);
  } else {
    cipher.init(Cipher.DECRYPT_MODE, key);
  byte[] serialized = cipher.doFinal(encryptedContent);
  throw new NoSuchAlgorithmException(e.toString());
} catch (InvalidAlgorithmParameterException e) {
  throw new NoSuchAlgorithmException(e.toString());
} catch (IllegalBlockSizeException e) {
  throw new NoSuchAlgorithmException(e.toString());
} catch (BadPaddingException e) {
  throw new NoSuchAlgorithmException(e.toString());
} catch (IllegalStateException  e) {
origin: org.xipki/security

@Override
public byte[] getSignature() {
 try {
  return cipher.doFinal();
 } catch (IllegalBlockSizeException ex) {
  throw new IllegalStateException("IllegalBlockSizeException: " + ex.getMessage());
 } catch (BadPaddingException ex) {
  throw new IllegalStateException("BadPaddingException: " + ex.getMessage());
 }
}
javax.cryptoBadPaddingException

Javadoc

The exception that is thrown when a padding mechanism is expected for the input data, but the input data does not have the proper padding bytes.

Most used methods

  • getMessage
  • printStackTrace
  • <init>
    Creates a new instance of BadPaddingException with a message.
  • toString
  • getLocalizedMessage
  • getCause
  • initCause

Popular in Java

  • Finding current android device location
  • getExternalFilesDir (Context)
  • compareTo (BigDecimal)
  • putExtra (Intent)
  • Window (java.awt)
    A Window object is a top-level window with no borders and no menubar. The default layout for a windo
  • BufferedInputStream (java.io)
    A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the i
  • Collection (java.util)
    Collection is the root of the collection hierarchy. It defines operations on data collections and t
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • Set (java.util)
    A Set is a data structure which does not allow duplicate elements.
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now