本文整理汇总了Java中javax.crypto.BadPaddingException类的典型用法代码示例。如果您正苦于以下问题:Java BadPaddingException类的具体用法?Java BadPaddingException怎么用?Java BadPaddingException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BadPaddingException类属于javax.crypto包,在下文中一共展示了BadPaddingException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import javax.crypto.BadPaddingException; //导入依赖的package包/类
public static void main(final String[] argv) throws IOException, InvalidKeySpecException, NoSuchPaddingException,
InvalidKeyException, InvalidParameterSpecException, IllegalBlockSizeException, BadPaddingException,
InvalidAlgorithmParameterException, ClassNotFoundException, GeneralSecurityException {
if(argv.length >= 2) {
ip = argv[0];
port = Integer.parseInt(argv[1]);
} else {
Logger.getLogger(Main.class.getName()).log(Level.INFO, "Default ip and port were applied.");
ip = Parameters.RELAY_IP;
port = Parameters.RELAY_PORT_WALLET_LISTENER;
}
// Init connection with relay
try {
RelayConnection.getInstance();
} catch(IOException ex) {
Logger.getLogger(Main.class.getName()).severe(ex.getMessage());
return;
}
new ClientApplication();
}
示例2: cipherOperation
import javax.crypto.BadPaddingException; //导入依赖的package包/类
/**
* Encrypt or decrypt byte[] data using the specified key
*/
private static byte[] cipherOperation(int opMode, Key key, byte[] data)
{
try
{
return createTheCipherInstance(opMode, key.getAlgorithm(), key).doFinal(data);
}
catch (IllegalBlockSizeException illegalblocksizeexception)
{
illegalblocksizeexception.printStackTrace();
}
catch (BadPaddingException badpaddingexception)
{
badpaddingexception.printStackTrace();
}
LOGGER.error("Cipher data failed!");
return null;
}
示例3: decrypt
import javax.crypto.BadPaddingException; //导入依赖的package包/类
public String decrypt(final String alias, final byte[] encryptedData, Context appContext)
throws UnrecoverableEntryException, NoSuchAlgorithmException, KeyStoreException,
NoSuchProviderException, NoSuchPaddingException, InvalidKeyException, IOException,
BadPaddingException, IllegalBlockSizeException, InvalidAlgorithmParameterException {
final Cipher cipher = Cipher.getInstance(TRANSFORMATION);
String IV = PreferenceHelper.getPrefernceHelperInstace().getString(appContext, "IV", "");
if (null != IV && !IV.isEmpty()) {
byte[] encryptionIv = Base64.decode(IV, Base64.DEFAULT);
Log.e("Decrypter", "IV : " + IV + " IV size " + encryptionIv.length);
final GCMParameterSpec spec = new GCMParameterSpec(128, encryptionIv);
cipher.init(Cipher.DECRYPT_MODE, getSecretKey(alias), spec);
return new String(cipher.doFinal(encryptedData), "UTF-8");
} else {
return "{}";
}
}
开发者ID:hiteshsahu,项目名称:FingerPrint-Authentication-With-React-Native-Android,代码行数:19,代码来源:Decrypter.java
示例4: mgf1
import javax.crypto.BadPaddingException; //导入依赖的package包/类
/**
* Compute MGF1 using mgfMD as the message digest.
* Note that we combine MGF1 with the XOR operation to reduce data
* copying.
*
* We generate maskLen bytes of MGF1 from the seed and XOR it into
* out[] starting at outOfs;
*/
private void mgf1(byte[] seed, int seedOfs, int seedLen,
byte[] out, int outOfs, int maskLen) throws BadPaddingException {
byte[] C = new byte[4]; // 32 bit counter
byte[] digest = new byte[mgfMd.getDigestLength()];
while (maskLen > 0) {
mgfMd.update(seed, seedOfs, seedLen);
mgfMd.update(C);
try {
mgfMd.digest(digest, 0, digest.length);
} catch (DigestException e) {
// should never happen
throw new BadPaddingException(e.toString());
}
for (int i = 0; (i < digest.length) && (maskLen > 0); maskLen--) {
out[outOfs++] ^= digest[i++];
}
if (maskLen > 0) {
// increment counter
for (int i = C.length - 1; (++C[i] == 0) && (i > 0); i--) {
// empty
}
}
}
}
示例5: engineDoFinal
import javax.crypto.BadPaddingException; //导入依赖的package包/类
@Override
protected int engineDoFinal(byte[] input, int inputOffset,
int inputLen, byte[] output, int outputOffset)
throws ShortBufferException, IllegalBlockSizeException,
BadPaddingException {
byte tmpOut[];
if (debug.DEBUG)
log("final (in offset: " + inputOffset + ", len: " +
inputLen + ", out offset: " + outputOffset + ")");
tmpOut = wolfCryptFinal(input, inputOffset, inputLen);
System.arraycopy(tmpOut, 0, output, outputOffset, tmpOut.length);
return tmpOut.length;
}
示例6: getKey
import javax.crypto.BadPaddingException; //导入依赖的package包/类
public Key getKey(PrivateKey privatekey) throws MeviusCipherException {
try {
Cipher c = Cipher.getInstance("RSA/ECB/PKCS1PADDING", "SunJCE");
c.init(Cipher.DECRYPT_MODE, privatekey);
/*
* DESedeKeySpec desKeySpec = new DESedeKeySpec((byte[]) (convertByte(key, c)));
* SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede"); return
* keyFactory.generateSecret(desKeySpec);
*/
return (Key) convertByte(key, c);
} catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchProviderException | NoSuchPaddingException
| ClassNotFoundException | IOException | IllegalBlockSizeException | BadPaddingException e) {
e.printStackTrace();
throw new MeviusCipherException(e.getMessage());
}
}
示例7: decrypt
import javax.crypto.BadPaddingException; //导入依赖的package包/类
public static String decrypt(String str) {
if (str == null) return null;
Cipher cipher;
try {
cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, keySpec,
new IvParameterSpec(ips.getBytes("UTF-8")));
byte[] byteStr = Base64.decodeBase64(str.getBytes());
return new String(cipher.doFinal(byteStr), "UTF-8");
} catch (NoSuchAlgorithmException | NoSuchPaddingException
| InvalidKeyException | InvalidAlgorithmParameterException
| IllegalBlockSizeException | BadPaddingException
| UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
示例8: engineDoFinal
import javax.crypto.BadPaddingException; //导入依赖的package包/类
protected byte[] engineDoFinal(
byte[] input,
int inputOffset,
int inputLen)
throws BadPaddingException, IllegalBlockSizeException
{
if (inputLen != 0)
{
byte[] out = engineUpdate(input, inputOffset, inputLen);
cipher.reset();
return out;
}
cipher.reset();
return new byte[0];
}
示例9: encrypt
import javax.crypto.BadPaddingException; //导入依赖的package包/类
public byte[] encrypt(int version, byte[] data) {
CryptVersion cryptVersion = cryptVersion(version);
try {
int cryptedLength = cryptVersion.encryptedLength.apply(data.length);
byte[] result = new byte[cryptedLength + cryptVersion.saltLength + 1];
result[0] = toSignedByte(version);
byte[] random = urandomBytes(cryptVersion.saltLength);
IvParameterSpec iv_spec = new IvParameterSpec(random);
System.arraycopy(random, 0, result, 1, cryptVersion.saltLength);
Cipher cipher = cipher(cryptVersion.cipher);
cipher.init(Cipher.ENCRYPT_MODE, cryptVersion.key, iv_spec);
int len = cipher.doFinal(data, 0, data.length, result, cryptVersion.saltLength + 1);
if (len < cryptedLength) LOG.info("len was " + len + " instead of " + cryptedLength);
return result;
} catch (ShortBufferException | IllegalBlockSizeException | BadPaddingException | InvalidAlgorithmParameterException | InvalidKeyException e) {
throw new RuntimeException("JCE exception caught while encrypting with version " + version, e);
}
}
示例10: engineWrap
import javax.crypto.BadPaddingException; //导入依赖的package包/类
protected byte[] engineWrap(
Key key)
throws IllegalBlockSizeException, InvalidKeyException
{
byte[] encoded = key.getEncoded();
if (encoded == null)
{
throw new InvalidKeyException("Cannot wrap key, null encoding.");
}
try
{
if (wrapEngine == null)
{
return engineDoFinal(encoded, 0, encoded.length);
}
else
{
return wrapEngine.wrap(encoded, 0, encoded.length);
}
}
catch (BadPaddingException e)
{
throw new IllegalBlockSizeException(e.getMessage());
}
}
示例11: engineWrap
import javax.crypto.BadPaddingException; //导入依赖的package包/类
/**
* Wrap a key.
*
* @param key the key to be wrapped.
*
* @return the wrapped key.
*
* @exception IllegalBlockSizeException if this cipher is a block
* cipher, no padding has been requested, and the length of the
* encoding of the key to be wrapped is not a
* multiple of the block size.
*
* @exception InvalidKeyException if it is impossible or unsafe to
* wrap the key with this cipher (e.g., a hardware protected key is
* being passed to a software only cipher).
*/
protected final byte[] engineWrap(Key key)
throws IllegalBlockSizeException, InvalidKeyException
{
byte[] result = null;
try {
byte[] encodedKey = key.getEncoded();
if ((encodedKey == null) || (encodedKey.length == 0)) {
throw new InvalidKeyException("Cannot get an encoding of " +
"the key to be wrapped");
}
result = engineDoFinal(encodedKey, 0, encodedKey.length);
} catch (BadPaddingException e) {
// Should never happen
}
return result;
}
示例12: engineDoFinal
import javax.crypto.BadPaddingException; //导入依赖的package包/类
protected byte[] engineDoFinal(
byte[] input,
int inputOffset,
int inputLen)
throws IllegalBlockSizeException, BadPaddingException
{
if (inputLen != 0)
{
buffer.write(input, inputOffset, inputLen);
}
try
{
byte[] buf = buffer.toByteArray();
buffer.reset();
return cipher.processBlock(buf, 0, buf.length);
}
catch (InvalidCipherTextException e)
{
throw new BadPaddingException(e.getMessage());
}
}
示例13: engineDoFinal
import javax.crypto.BadPaddingException; //导入依赖的package包/类
protected byte[] engineDoFinal(
byte[] input,
int inputOffset,
int inputLen)
throws IllegalBlockSizeException, BadPaddingException
{
cipher.processBytes(input, inputOffset, inputLen);
try
{
return cipher.doFinal();
}
catch (InvalidCipherTextException e)
{
throw new BadPaddingException(e.getMessage());
}
}
示例14: decrypt
import javax.crypto.BadPaddingException; //导入依赖的package包/类
public byte[] decrypt(byte[] data) {
int version = fromSignedByte(data[0]);
CryptVersion cryptVersion = cryptVersion(version);
try {
byte[] random = new byte[cryptVersion.saltLength];
System.arraycopy(data, 1, random, 0, cryptVersion.saltLength);
IvParameterSpec iv_spec = new IvParameterSpec(random);
Cipher cipher = cipher(cryptVersions[version].cipher);
cipher.init(Cipher.DECRYPT_MODE, cryptVersions[version].key, iv_spec);
return cipher.doFinal(data, cryptVersion.saltLength + 1, data.length - cryptVersion.saltLength - 1);
} catch (InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException e) {
throw new RuntimeException("JCE exception caught while decrypting with version " + version, e);
}
}
示例15: wrap
import javax.crypto.BadPaddingException; //导入依赖的package包/类
/**
* Wrap a key.
*
* @param key the key to be wrapped.
*
* @return the wrapped key.
*
* @exception IllegalBlockSizeException if this cipher is a block
* cipher, no padding has been requested, and the length of the
* encoding of the key to be wrapped is not a
* multiple of the block size.
*
* @exception InvalidKeyException if it is impossible or unsafe to
* wrap the key with this cipher (e.g., a hardware protected key is
* being passed to a software only cipher).
*/
byte[] wrap(Key key)
throws IllegalBlockSizeException, InvalidKeyException {
byte[] result = null;
try {
byte[] encodedKey = key.getEncoded();
if ((encodedKey == null) || (encodedKey.length == 0)) {
throw new InvalidKeyException("Cannot get an encoding of " +
"the key to be wrapped");
}
result = doFinal(encodedKey, 0, encodedKey.length);
} catch (BadPaddingException e) {
// Should never happen
}
return result;
}