本文整理了Java中javax.crypto.BadPaddingException
类的一些代码示例,展示了BadPaddingException
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BadPaddingException
类的具体详情如下:
包路径:javax.crypto.BadPaddingException
类名称:BadPaddingException
[英]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.
[中]当输入数据需要填充机制,但输入数据没有正确的填充字节时引发的异常。
代码示例来源: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());
}
}
内容来源于网络,如有侵权,请联系作者删除!