当前位置: 首页>>代码示例>>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;未经允许,请勿转载。