當前位置: 首頁>>代碼示例>>Java>>正文


Java BadPaddingException類代碼示例

本文整理匯總了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();

}
 
開發者ID:StanIsAdmin,項目名稱:CrashCoin,代碼行數:25,代碼來源:Main.java

示例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;
}
 
開發者ID:SkidJava,項目名稱:BaseClient,代碼行數:22,代碼來源:CryptManager.java

示例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
            }
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:33,代碼來源:RSAPadding.java

示例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;
}
 
開發者ID:wolfSSL,項目名稱:wolfcrypt-jni,代碼行數:19,代碼來源:WolfCryptCipher.java

示例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());
	}
}
 
開發者ID:biancso,項目名稱:Mevius-IO,代碼行數:17,代碼來源:MeviusTransferPacket.java

示例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;
}
 
開發者ID:JoMingyu,項目名稱:Daejeon-People,代碼行數:20,代碼來源:AES256.java

示例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];
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:20,代碼來源:JCEStreamCipher.java

示例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);
    }
}
 
開發者ID:bolcom,項目名稱:spring-data-mongodb-encrypt,代碼行數:23,代碼來源:CryptVault.java

示例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());
    }
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:27,代碼來源:BaseWrapCipher.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:36,代碼來源:CipherWithWrappingSpi.java

示例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());
    }
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:25,代碼來源:CipherSpi.java

示例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());
    }
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:17,代碼來源:CipherSpi.java

示例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);
    }
}
 
開發者ID:bolcom,項目名稱:spring-data-mongodb-encrypt,代碼行數:17,代碼來源:CryptVault.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:33,代碼來源:CipherCore.java


注:本文中的javax.crypto.BadPaddingException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。