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


Java IllegalBlockSizeException類代碼示例

本文整理匯總了Java中javax.crypto.IllegalBlockSizeException的典型用法代碼示例。如果您正苦於以下問題:Java IllegalBlockSizeException類的具體用法?Java IllegalBlockSizeException怎麽用?Java IllegalBlockSizeException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


IllegalBlockSizeException類屬於javax.crypto包,在下文中一共展示了IllegalBlockSizeException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: decrypt

import javax.crypto.IllegalBlockSizeException; //導入依賴的package包/類
private String decrypt(String text) throws GeneralSecurityException {
    SecretKeySpec skeySpec = new SecretKeySpec(
            Base64.decodeBase64(ENCRYPTION_KEY), "AES");

    byte[] result;
    try {
        byte[] decoded = Base64.decodeBase64(text.getBytes());
        Cipher cipher = Cipher.getInstance("AES");
        cipher.init(Cipher.DECRYPT_MODE, skeySpec);
        result = cipher.doFinal(decoded);
    } catch (InvalidKeyException | NoSuchAlgorithmException
            | NoSuchPaddingException | IllegalBlockSizeException
            | BadPaddingException e) {
        throw new GeneralSecurityException(
                "unable to decrypt old encryption");
    }

    return new String(result);
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:20,代碼來源:PasswordSetup.java

示例2: cipherOperation

import javax.crypto.IllegalBlockSizeException; //導入依賴的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: main

import javax.crypto.IllegalBlockSizeException; //導入依賴的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

示例4: testEncryptionHelper

import javax.crypto.IllegalBlockSizeException; //導入依賴的package包/類
@Test
public void testEncryptionHelper() throws NoSuchPaddingException, BadPaddingException, InvalidKeyException, NoSuchAlgorithmException,
        IllegalBlockSizeException, UnsupportedEncodingException, InvalidAlgorithmParameterException, DecoderException {

    // https://golang.org/src/crypto/cipher/gcm_test.go
    String[][] testCases = new String[][]{
            new String[]{"11754cd72aec309bf52f7687212e8957", "3c819d9a9bed087615030b65", "", "250327c674aaf477aef2675748cf6971"},
            new String[]{"ca47248ac0b6f8372a97ac43508308ed", "ffd2b598feabc9019262d2be", "", "60d20404af527d248d893ae495707d1a"},
            new String[]{"7fddb57453c241d03efbed3ac44e371c", "ee283a3fc75575e33efd4887", "d5de42b461646c255c87bd2962d3b9a2", "2ccda4a5415cb91e135c2a0f78c9b2fdb36d1df9b9d5e596f83e8b7f52971cb3"},
            new String[]{"ab72c77b97cb5fe9a382d9fe81ffdbed", "54cc7dc2c37ec006bcc6d1da", "007c5e5b3e59df24a7c355584fc1518d", "0e1bde206a07a9c2c1b65300f8c649972b4401346697138c7a4891ee59867d0c"},
            new String[]{"feffe9928665731c6d6a8f9467308308", "cafebabefacedbaddecaf888", "d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b391aafd255",
                    "42831ec2217774244b7221b784d0d49ce3aa212f2c02a4e035c17e2329aca12e21d514b25466931c7d8f6a5aac84aa051ba30b396a0aac973d58e091473f59854d5c2af327cd64a62cf35abd2ba6fab4"},
    };
    for (String[] testCase : testCases) {

        SecretKeySpec k = new SecretKeySpec(new Hex().decode(testCase[0].getBytes()), "AES");
        IvParameterSpec iv = new IvParameterSpec(new Hex().decode(testCase[1].getBytes()));

        byte[] cipherTExt = EncryptionHelper.encrypt(k, iv, new Hex().decode(testCase[2].getBytes()));
        String cipher = new String(new Hex().encode(cipherTExt));

        assertEquals(cipher, testCase[3]);
        assertEquals(testCase[2], new String(new Hex().encode(EncryptionHelper.decrypt(k, iv, cipherTExt))));
    }
}
 
開發者ID:privacyidea,項目名稱:privacyidea-authenticator,代碼行數:26,代碼來源:ApplicationTest.java

示例5: encrypt

import javax.crypto.IllegalBlockSizeException; //導入依賴的package包/類
public static String encrypt(String str) {
    if (str == null) return null;
    Cipher cipher;
    try {
        cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        cipher.init(Cipher.ENCRYPT_MODE, keySpec,
                new IvParameterSpec(ips.getBytes("UTF-8")));

        byte[] encrypted = cipher.doFinal(str.getBytes("UTF-8"));
        String Str = new String(Base64.encodeBase64(encrypted));
        return Str;
    } catch (NoSuchAlgorithmException | NoSuchPaddingException
            | InvalidKeyException | InvalidAlgorithmParameterException
            | IllegalBlockSizeException | BadPaddingException
            | UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:JoMingyu,項目名稱:Daejeon-People,代碼行數:20,代碼來源:AES.java

示例6: cipherOperation

import javax.crypto.IllegalBlockSizeException; //導入依賴的package包/類
/**
 * Encrypt or decrypt byte[] data using the specified key
 */
private static byte[] cipherOperation(int opMode, Key key, byte[] data)
{
    try
    {
        /**
         * Creates the Cipher Instance.
         */
        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:F1r3w477,項目名稱:CustomWorldGen,代碼行數:25,代碼來源:CryptManager.java

示例7: decryptStr

import javax.crypto.IllegalBlockSizeException; //導入依賴的package包/類
/**
 * decrypt string
 * @see #encryptStr(String)
 * @param encryptStr 1
 * @return 1
 * @throws InvalidKeyException 1
 * @throws IllegalBlockSizeException 1
 * @throws BadPaddingException 1
 * @throws NullPointerException if encryptStr is null
 */
public String decryptStr(String encryptStr) throws InvalidKeyException, IllegalBlockSizeException, BadPaddingException
{
    if(encryptStr == null)
    {
        throw new NullPointerException();
    }
    
    encryptStr = encryptStr.toUpperCase();
    
    ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
    int len = encryptStr.length();
    for(int i = 0; i < len; i += 2)
    {
        int b = ((charToByte(encryptStr.charAt(i)) << 4) & 0xff) | charToByte(encryptStr.charAt(i + 1));
        byteOut.write(b);
    }
    
    return decryptStr(byteOut.toByteArray());
}
 
開發者ID:LinuxSuRen,項目名稱:phoenix.webui.framework,代碼行數:30,代碼來源:Encryptor.java

示例8: engineWrap

import javax.crypto.IllegalBlockSizeException; //導入依賴的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

示例9: flush

import javax.crypto.IllegalBlockSizeException; //導入依賴的package包/類
@Override
public void flush() throws IOException {
  try {
    byte[] ciphertext = cipher.doFinal();
    byte[] auth       = mac.doFinal(ciphertext);

    messageDigest.update(ciphertext);
    this.digest = messageDigest.digest(auth);

    outputStream.write(ciphertext);
    outputStream.write(auth);

    ciphertextLength += ciphertext.length;
    ciphertextLength += auth.length;

    outputStream.flush();
  } catch (IllegalBlockSizeException | BadPaddingException e) {
    throw new AssertionError(e);
  }
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-lib,代碼行數:21,代碼來源:AttachmentCipherOutputStream.java

示例10: main

import javax.crypto.IllegalBlockSizeException; //導入依賴的package包/類
public static void main(String[] args) throws InvalidKeyException, DataLengthException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException, IllegalStateException, InvalidCipherTextException
	{

		try 
		{
			UIManager.setLookAndFeel("com.pagosoft.plaf.PgsLookAndFeel");
		}

		catch (Exception e)
		{
			;
		}
		GUI MainGUI = new GUI();
		MainGUI.ConstructGUI();
		
//		String CT = TextEncrypt.CBCDecrypt("8mjf2sqScPChi5lJQut6U5phB6IW8ze90WdqDm+ulLU1NWI2ODZlYzVmMjYxYTA5", "secret", 256, 0, "Q");
//		
//		System.out.println(CT);

	}
 
開發者ID:MonroCoury,項目名稱:CryptoKnight,代碼行數:21,代碼來源:Main.java

示例11: CBCEncrypt

import javax.crypto.IllegalBlockSizeException; //導入依賴的package包/類
public static String CBCEncrypt(int alg, int KeySize, String inFile, String pwd, String mode) throws NoSuchAlgorithmException, InvalidKeySpecException, DataLengthException, IllegalStateException, InvalidCipherTextException, IOException, InvalidKeyException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException
{
	String res = "";
	
	byte[] plain = loadFile(inFile);
	
	Encryptor enc = new Encryptor();
	enc.setParameters(KeySize, alg);
	enc.setEncParameters(alg, pwd, KeySize, mode);
	byte[] bytesRes = enc.CBCEncrypt(plain, alg);
	
	save2File(inFile + ".enc", bytesRes);
	
	res = "Done! file contents encrypted and saved to a corresponding enc file!"; 
	return res;
}
 
開發者ID:MonroCoury,項目名稱:CryptoKnight,代碼行數:17,代碼來源:FileEncrypt.java

示例12: decrypt

import javax.crypto.IllegalBlockSizeException; //導入依賴的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

示例13: getSignedData

import javax.crypto.IllegalBlockSizeException; //導入依賴的package包/類
public String getSignedData(String b64data) {
    PrivateKey privkey = getKeystoreKey();
    byte[] data = Base64.decode(b64data, Base64.DEFAULT);
    // The Jelly Bean *evil* Hack
    // 4.2 implements the RSA/ECB/PKCS1PADDING in the OpenSSLprovider
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN) {
        return processSignJellyBeans(privkey, data);
    }
    try {
        /* ECB is perfectly fine in this special case, since we are using it for
           the public/private part in the TLS exchange
         */
        @SuppressLint("GetInstance") Cipher rsaSigner = Cipher.getInstance("RSA/ECB/PKCS1PADDING");
        rsaSigner.init(Cipher.ENCRYPT_MODE, privkey);
        byte[] signed_bytes = rsaSigner.doFinal(data);
        return Base64.encodeToString(signed_bytes, Base64.NO_WRAP);
    } catch (NoSuchAlgorithmException | InvalidKeyException | IllegalBlockSizeException
            | BadPaddingException | NoSuchPaddingException e) {
        VpnStatus.logError(R.string.error_rsa_sign, e.getClass().toString(), e.getLocalizedMessage());
        return null;
    }
}
 
開發者ID:akashdeepsingh9988,項目名稱:Cybernet-VPN,代碼行數:23,代碼來源:VpnProfile.java

示例14: engineDoFinal

import javax.crypto.IllegalBlockSizeException; //導入依賴的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

示例15: engineWrap

import javax.crypto.IllegalBlockSizeException; //導入依賴的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
    {
        return engineDoFinal(encoded, 0, encoded.length);
    }
    catch (BadPaddingException e)
    {
        throw new IllegalBlockSizeException(e.getMessage());
    }
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:20,代碼來源:JCEStreamCipher.java


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