当前位置: 首页>>代码示例>>Java>>正文


Java InvalidCipherTextException类代码示例

本文整理汇总了Java中org.bouncycastle.crypto.InvalidCipherTextException的典型用法代码示例。如果您正苦于以下问题:Java InvalidCipherTextException类的具体用法?Java InvalidCipherTextException怎么用?Java InvalidCipherTextException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


InvalidCipherTextException类属于org.bouncycastle.crypto包,在下文中一共展示了InvalidCipherTextException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.bouncycastle.crypto.InvalidCipherTextException; //导入依赖的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

示例2: CBCEncrypt

import org.bouncycastle.crypto.InvalidCipherTextException; //导入依赖的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

示例3: CBCDecrypt

import org.bouncycastle.crypto.InvalidCipherTextException; //导入依赖的package包/类
public static String CBCDecrypt(int alg, int KeySize, String inFile, String pwd, String mode) throws NoSuchAlgorithmException, InvalidKeySpecException, DataLengthException, IllegalStateException, InvalidCipherTextException, IOException
{
	String res = "";
	
	if (checkFile(inFile.substring(0, inFile.lastIndexOf("."))))
	{
		res = "A file with the same name already exists! Rename or move it to avoid losing your data!";
		return res;
	}
	
	byte[] Encrypted = loadFile(inFile);
	
	
	Encryptor enc = new Encryptor();
	enc.setParameters(KeySize, alg);
	enc.setDecParameters(Encrypted, alg, pwd, KeySize, mode);
	byte[] bytesRes = enc.CBCDecrypt(Encrypted, alg);
	
	save2File(inFile.substring(0, inFile.lastIndexOf(".")), bytesRes);
	
	res = "Done! file contents decrypted and saved to the specified directory!"; 
	return res;
}
 
开发者ID:MonroCoury,项目名称:CryptoKnight,代码行数:24,代码来源:FileEncrypt.java

示例4: padCount

import org.bouncycastle.crypto.InvalidCipherTextException; //导入依赖的package包/类
/**
 * return the number of pad bytes present in the block.
 */
public int padCount(byte[] in)
    throws InvalidCipherTextException
{
    int count = in[in.length - 1] & 0xff;

    if (count > in.length || count == 0)
    {
        throw new InvalidCipherTextException("pad block corrupted");
    }
    
    for (int i = 1; i <= count; i++)
    {
        if (in[in.length - i] != count)
        {
            throw new InvalidCipherTextException("pad block corrupted");
        }
    }

    return count;
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:24,代码来源:PKCS7Padding.java

示例5: generateUnwrappedKey

import org.bouncycastle.crypto.InvalidCipherTextException; //导入依赖的package包/类
public GenericKey generateUnwrappedKey(AlgorithmIdentifier encryptedKeyAlgorithm, byte[] encryptedKey)
    throws OperatorException
{
    AsymmetricBlockCipher keyCipher = createAsymmetricUnwrapper(this.getAlgorithmIdentifier().getAlgorithm());

    keyCipher.init(false, privateKey);
    try
    {
        byte[] key = keyCipher.processBlock(encryptedKey, 0, encryptedKey.length);

        if (encryptedKeyAlgorithm.getAlgorithm().equals(PKCSObjectIdentifiers.des_EDE3_CBC))
        {
            return new GenericKey(encryptedKeyAlgorithm, key);
        }
        else
        {
            return new GenericKey(encryptedKeyAlgorithm, key);
        }
    }
    catch (InvalidCipherTextException e)
    {
        throw new OperatorException("unable to recover secret key: " + e.getMessage(), e);
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:25,代码来源:BcAsymmetricKeyUnwrapper.java

示例6: processBlock

import org.bouncycastle.crypto.InvalidCipherTextException; //导入依赖的package包/类
public byte[] processBlock(byte[] in, int inOff, int len)
    throws InvalidCipherTextException
{
    byte[] tmp = new byte[len];

    System.arraycopy(in, inOff, tmp, 0, len);

    if (forEncryption)
    {
        return encrypt(tmp, pubKey);
    }
    else
    {
        return decrypt(tmp, privKey);
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:17,代码来源:NTRUEngine.java

示例7: decryptPreMasterSecret

import org.bouncycastle.crypto.InvalidCipherTextException; //导入依赖的package包/类
public byte[] decryptPreMasterSecret(byte[] encryptedPreMasterSecret)
    throws IOException
{

    PKCS1Encoding encoding = new PKCS1Encoding(new RSABlindedEngine());
    encoding.init(false, new ParametersWithRandom(this.privateKey, context.getSecureRandom()));

    try
    {
        return encoding.processBlock(encryptedPreMasterSecret, 0,
            encryptedPreMasterSecret.length);
    }
    catch (InvalidCipherTextException e)
    {
        throw new TlsFatalAlert(AlertDescription.illegal_parameter);
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:18,代码来源:DefaultTlsEncryptionCredentials.java

示例8: padCount

import org.bouncycastle.crypto.InvalidCipherTextException; //导入依赖的package包/类
/**
 * return the number of pad bytes present in the block.
 */
public int padCount(byte[] in)
    throws InvalidCipherTextException
{
    int count = in.length;

    while (count > 0)
    {
        if (in[count - 1] != 0)
        {
            break;
        }

        count--;
    }

    return in.length - count;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:21,代码来源:ZeroBytePadding.java

示例9: padCount

import org.bouncycastle.crypto.InvalidCipherTextException; //导入依赖的package包/类
/**
 * return the number of pad bytes present in the block.
 */
public int padCount(byte[] in)
    throws InvalidCipherTextException
{
    int count = in.length - 1;

    while (count > 0 && in[count] == 0)
    {
        count--;
    }

    if (in[count] != (byte)0x80)
    {
        throw new InvalidCipherTextException("pad block corrupted");
    }
    
    return in.length - count;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:21,代码来源:ISO7816d4Padding.java

示例10: engineDoFinal

import org.bouncycastle.crypto.InvalidCipherTextException; //导入依赖的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

示例11: engineDoFinal

import org.bouncycastle.crypto.InvalidCipherTextException; //导入依赖的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

示例12: extractSecretKey

import org.bouncycastle.crypto.InvalidCipherTextException; //导入依赖的package包/类
protected KeyParameter extractSecretKey(AlgorithmIdentifier keyEncryptionAlgorithm, AlgorithmIdentifier contentEncryptionAlgorithm, byte[] derivedKey, byte[] encryptedContentEncryptionKey)
    throws CMSException
{
    Wrapper keyEncryptionCipher = EnvelopedDataHelper.createRFC3211Wrapper(keyEncryptionAlgorithm.getAlgorithm());

    keyEncryptionCipher.init(false, new ParametersWithIV(new KeyParameter(derivedKey), ASN1OctetString.getInstance(keyEncryptionAlgorithm.getParameters()).getOctets()));

    try
    {
        return new KeyParameter(keyEncryptionCipher.unwrap(encryptedContentEncryptionKey, 0, encryptedContentEncryptionKey.length));
    }
    catch (InvalidCipherTextException e)
    {
        throw new CMSException("unable to unwrap key: " + e.getMessage(), e);
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:17,代码来源:BcPasswordRecipient.java

示例13: aesEncrypt

import org.bouncycastle.crypto.InvalidCipherTextException; //导入依赖的package包/类
public static byte[] aesEncrypt(byte[] plaintext, byte[] myPrivateKey, byte[] theirPublicKey, byte[] nonce) {
    try {
        byte[] dhSharedSecret = new byte[32];
        Curve25519.curve(dhSharedSecret, myPrivateKey, theirPublicKey);
        for (int i = 0; i < 32; i++) {
            dhSharedSecret[i] ^= nonce[i];
        }
        byte[] key = sha256().digest(dhSharedSecret);
        byte[] iv = new byte[16];
        secureRandom.get().nextBytes(iv);
        PaddedBufferedBlockCipher aes = new PaddedBufferedBlockCipher(new CBCBlockCipher(
                new AESEngine()));
        CipherParameters ivAndKey = new ParametersWithIV(new KeyParameter(key), iv);
        aes.init(true, ivAndKey);
        byte[] output = new byte[aes.getOutputSize(plaintext.length)];
        int ciphertextLength = aes.processBytes(plaintext, 0, plaintext.length, output, 0);
        ciphertextLength += aes.doFinal(output, ciphertextLength);
        byte[] result = new byte[iv.length + ciphertextLength];
        System.arraycopy(iv, 0, result, 0, iv.length);
        System.arraycopy(output, 0, result, iv.length, ciphertextLength);
        return result;
    } catch (InvalidCipherTextException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:26,代码来源:Crypto.java

示例14: finish

import org.bouncycastle.crypto.InvalidCipherTextException; //导入依赖的package包/类
/**
 * Finishes and voids this cipher output stream.
 * Calling this method causes all remaining buffered bytes to get written
 * and padded if necessary.
 * Afterwards, this stream will behave as if it had been closed, although
 * the decorated stream may still be open.
 *
 * @throws IOException If {@code out} or {@code cipher} aren't properly
 *         initialized, an I/O error occurs or the cipher
 *         text is invalid because some required padding is missing.
 */
public void finish() throws IOException {
    final BufferedBlockCipher cipher = this.cipher;
    if (null == cipher)
        return;
    this.cipher = null;

    int cipherLen = cipher.getOutputSize(0);
    byte[] cipherOut = this.buffer;
    if (cipherLen > cipherOut.length)
        this.buffer = cipherOut = new byte[cipherLen];
    try {
        cipherLen = cipher.doFinal(cipherOut, 0);
    } catch (InvalidCipherTextException ex) {
        throw new IOException(ex);
    }
    out.write(cipherOut, 0, cipherLen);
}
 
开发者ID:christian-schlichtherle,项目名称:truevfs,代码行数:29,代码来源:CipherOutputStream.java

示例15: aesDecrypt

import org.bouncycastle.crypto.InvalidCipherTextException; //导入依赖的package包/类
public static byte[] aesDecrypt(byte[] ivCiphertext, byte[] myPrivateKey, byte theirPublicKey[]) {
    try {
        if (ivCiphertext.length < 16 || ivCiphertext.length % 16 != 0) {
            throw new InvalidCipherTextException("invalid ciphertext");
        }
        byte[] iv = Arrays.copyOfRange(ivCiphertext, 0, 16);
        byte[] ciphertext = Arrays.copyOfRange(ivCiphertext, 16, ivCiphertext.length);
        byte[] dhSharedSecret = new byte[32];
        Curve25519.curve(dhSharedSecret, myPrivateKey, theirPublicKey);
        byte[] key = sha256().digest(dhSharedSecret);
        PaddedBufferedBlockCipher aes = new PaddedBufferedBlockCipher(new CBCBlockCipher(
                new AESEngine()));
        CipherParameters ivAndKey = new ParametersWithIV(new KeyParameter(key), iv);
        aes.init(false, ivAndKey);
        byte[] output = new byte[aes.getOutputSize(ciphertext.length)];
        int plaintextLength = aes.processBytes(ciphertext, 0, ciphertext.length, output, 0);
        plaintextLength += aes.doFinal(output, plaintextLength);
        byte[] result = new byte[plaintextLength];
        System.arraycopy(output, 0, result, 0, result.length);
        return result;
    } catch (InvalidCipherTextException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
 
开发者ID:de-luxe,项目名称:burstcoin-faucet,代码行数:25,代码来源:Crypto.java


注:本文中的org.bouncycastle.crypto.InvalidCipherTextException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。