/** * Decrypt an encapsulated session key. * * @param in the input buffer for the encapsulated key. * @param keyLen the length of the session key. * @return the session key. */ public CipherParameters decrypt(byte[] in, int keyLen) { return decrypt(in, 0, in.length, keyLen); }
/** * Decrypt an encapsulated session key. * * @param in the input buffer for the encapsulated key. * @param keyLen the length of the session key. * @return the session key. */ public CipherParameters decrypt(byte[] in, int keyLen) { return decrypt(in, 0, in.length, keyLen); }
public static byte[] Decrypt(byte[] prikey, byte[] IV, byte[] key_cxt, byte[] ciphertext, int keylen) { try { com.github.ontio.account.Account account = new com.github.ontio.account.Account(prikey, signatureScheme); ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec((String) curveParaSpec[0]); ECDomainParameters ecDomain = new ECDomainParameters(spec.getCurve(), spec.getG(), spec.getN()); AsymmetricCipherKeyPair keys = new AsymmetricCipherKeyPair( null, new ECPrivateKeyParameters(((BCECPrivateKey) account.getPrivateKey()).getD(), ecDomain)); byte[] out = key_cxt; ECIESKeyEncapsulation kem = new ECIESKeyEncapsulation(new KDF2BytesGenerator(defaultDigest), new SecureRandom()); KeyParameter key1; kem.init(keys.getPrivate()); key1 = (KeyParameter) kem.decrypt(out, keylen); byte[] plaintext; try { Cipher dec = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC"); Key key = new SecretKeySpec(key1.getKey(), "AES"); dec.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(IV)); plaintext = dec.doFinal(ciphertext); } catch (Exception e) { throw new Exception("AES failed initialisation - " + e.toString(), e); } return plaintext; } catch (Exception e) { e.printStackTrace(); } return null; }
public static byte[] Decrypt(byte[] prikey, byte[] IV, byte[] key_cxt, byte[] ciphertext, int keylen) { try { com.github.ontio.account.Account account = new com.github.ontio.account.Account(prikey, signatureScheme); ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec((String) curveParaSpec[0]); ECDomainParameters ecDomain = new ECDomainParameters(spec.getCurve(), spec.getG(), spec.getN()); AsymmetricCipherKeyPair keys = new AsymmetricCipherKeyPair( null, new ECPrivateKeyParameters(((BCECPrivateKey) account.getPrivateKey()).getD(), ecDomain)); byte[] out = key_cxt; ECIESKeyEncapsulation kem = new ECIESKeyEncapsulation(new KDF2BytesGenerator(defaultDigest), new SecureRandom()); KeyParameter key1; kem.init(keys.getPrivate()); key1 = (KeyParameter) kem.decrypt(out, keylen); byte[] plaintext; try { Cipher dec = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC"); Key key = new SecretKeySpec(key1.getKey(), "AES"); dec.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(IV)); plaintext = dec.doFinal(ciphertext); } catch (Exception e) { throw new Exception("AES failed initialisation - " + e.toString(), e); } return plaintext; } catch (Exception e) { e.printStackTrace(); } return null; }