List of usage examples for org.bouncycastle.crypto InvalidCipherTextException InvalidCipherTextException
public InvalidCipherTextException(String message, Throwable cause)
From source file:org.ethereum.crypto.EthereumIESEngine.java
License:Open Source License
public byte[] processBlock(byte[] in, int inOff, int inLen, byte[] macData) throws InvalidCipherTextException { if (forEncryption) { if (keyPairGenerator != null) { EphemeralKeyPair ephKeyPair = keyPairGenerator.generate(); this.privParam = ephKeyPair.getKeyPair().getPrivate(); this.v = ephKeyPair.getEncodedPublicKey(); }/*from w ww . j av a 2s. c o m*/ } else { if (keyParser != null) { ByteArrayInputStream bIn = new ByteArrayInputStream(in, inOff, inLen); try { this.pubParam = keyParser.readKey(bIn); } catch (IOException e) { throw new InvalidCipherTextException( "unable to recover ephemeral public key: " + e.getMessage(), e); } int encLength = (inLen - bIn.available()); this.v = Arrays.copyOfRange(in, inOff, inOff + encLength); } } // Compute the common value and convert to byte array. agree.init(privParam); BigInteger z = agree.calculateAgreement(pubParam); byte[] Z = BigIntegers.asUnsignedByteArray(agree.getFieldSize(), z); // Create input to KDF. byte[] vz; // if (v.length != 0) // { // VZ = new byte[v.length + Z.length]; // System.arraycopy(v, 0, VZ, 0, v.length); // System.arraycopy(Z, 0, VZ, v.length, Z.length); // } // else { vz = Z; } // Initialise the KDF. DerivationParameters kdfParam; if (kdf instanceof MGF1BytesGeneratorExt) { kdfParam = new MGFParameters(vz); } else { kdfParam = new KDFParameters(vz, param.getDerivationV()); } kdf.init(kdfParam); return forEncryption ? encryptBlock(in, inOff, inLen, macData) : decryptBlock(in, inOff, inLen, macData); }
From source file:org.xipki.commons.security.pkcs11.P11PlainRSASigner.java
License:Open Source License
@Override public byte[] processBlock(final byte[] in, final int inOff, final int len) throws InvalidCipherTextException { byte[] content = new byte[getInputBlockSize()]; System.arraycopy(in, inOff, content, content.length - len, len); try {/*w w w.j a v a 2s . co m*/ P11Identity identity = param.getP11CryptService().getIdentity(param.getIdentityId()); return identity.sign(P11Constants.CKM_RSA_X_509, null, content); } catch (XiSecurityException | P11TokenException ex) { throw new InvalidCipherTextException(ex.getMessage(), ex); } }
From source file:org.xipki.commons.security.pkcs12.NssPlainRSASigner.java
License:Open Source License
@Override public byte[] processBlock(final byte[] in, final int inOff, final int len) throws InvalidCipherTextException { try {// w w w.jav a 2 s . co m return cipher.doFinal(in, 0, in.length); } catch (IllegalBlockSizeException | BadPaddingException ex) { throw new InvalidCipherTextException(ex.getMessage(), ex); } }
From source file:org.xipki.security.p11.P11PlainRSASigner.java
License:Open Source License
@Override public byte[] processBlock(final byte[] in, final int inOff, final int len) throws InvalidCipherTextException { byte[] content = new byte[getInputBlockSize()]; System.arraycopy(in, inOff, content, content.length - len, len); try {// www . java 2s. c o m return param.getP11CryptService().CKM_RSA_X509(content, param.getSlot(), param.getKeyId()); } catch (SignerException e) { throw new InvalidCipherTextException(e.getMessage(), e); } }