Java Code Examples for org.spongycastle.crypto.modes.SICBlockCipher#processBlock()
The following examples show how to use
org.spongycastle.crypto.modes.SICBlockCipher#processBlock() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ECKeySecp256k1.java From aion with MIT License | 5 votes |
/** * Decrypt cipher by AES in SIC(also know as CTR) mode * * @param cipher -proper cipher * @return decrypted cipher, equal length to the cipher. * @deprecated should not use EC private scalar value as an AES key */ public byte[] decryptAES(byte[] cipher) { if (privKey == null) { throw new MissingPrivateKeyException(); } if (!(privKey instanceof BCECPrivateKey)) { throw new UnsupportedOperationException("Cannot use the private key as an AES key"); } AESFastEngine engine = new AESFastEngine(); SICBlockCipher ctrEngine = new SICBlockCipher(engine); KeyParameter key = new KeyParameter( BigIntegers.asUnsignedByteArray(((BCECPrivateKey) privKey).getD())); ParametersWithIV params = new ParametersWithIV(key, new byte[16]); ctrEngine.init(false, params); int i = 0; byte[] out = new byte[cipher.length]; while (i < cipher.length) { ctrEngine.processBlock(cipher, i, out, i); i += engine.getBlockSize(); if (cipher.length - i < engine.getBlockSize()) { break; } } // process left bytes if (cipher.length - i > 0) { byte[] tmpBlock = new byte[16]; System.arraycopy(cipher, i, tmpBlock, 0, cipher.length - i); ctrEngine.processBlock(tmpBlock, 0, tmpBlock, 0); System.arraycopy(tmpBlock, 0, out, i, cipher.length - i); } return out; }
Example 2
Source File: ECKey.java From gsc-core with GNU Lesser General Public License v3.0 | 5 votes |
/** * Decrypt cipher by AES in SIC(also know as CTR) mode * * @param cipher -proper cipher * @return decrypted cipher, equal length to the cipher. * @deprecated should not use EC private scalar value as an AES key */ public byte[] decryptAES(byte[] cipher) { if (privKey == null) { throw new MissingPrivateKeyException(); } if (!(privKey instanceof BCECPrivateKey)) { throw new UnsupportedOperationException("Cannot use the private " + "key as an AES key"); } AESEngine engine = new AESEngine(); SICBlockCipher ctrEngine = new SICBlockCipher(engine); KeyParameter key = new KeyParameter(BigIntegers.asUnsignedByteArray(( (BCECPrivateKey) privKey).getD())); ParametersWithIV params = new ParametersWithIV(key, new byte[16]); ctrEngine.init(false, params); int i = 0; byte[] out = new byte[cipher.length]; while (i < cipher.length) { ctrEngine.processBlock(cipher, i, out, i); i += engine.getBlockSize(); if (cipher.length - i < engine.getBlockSize()) { break; } } // process left bytes if (cipher.length - i > 0) { byte[] tmpBlock = new byte[16]; System.arraycopy(cipher, i, tmpBlock, 0, cipher.length - i); ctrEngine.processBlock(tmpBlock, 0, tmpBlock, 0); System.arraycopy(tmpBlock, 0, out, i, cipher.length - i); } return out; }
Example 3
Source File: ECKey.java From wkcwallet-java with Apache License 2.0 | 5 votes |
/** * Decrypt cipher by AES in SIC(also know as CTR) mode * * @param cipher * -proper cipher * @return decrypted cipher, equal length to the cipher. * @deprecated should not use EC private scalar value as an AES key */ public byte[] decryptAES(byte[] cipher) { if (privKey == null) { throw new MissingPrivateKeyException(); } if (!(privKey instanceof BCECPrivateKey)) { throw new UnsupportedOperationException("Cannot use the private key as an AES key"); } AESFastEngine engine = new AESFastEngine(); SICBlockCipher ctrEngine = new SICBlockCipher(engine); KeyParameter key = new KeyParameter(BigIntegers.asUnsignedByteArray(((BCECPrivateKey) privKey).getD())); ParametersWithIV params = new ParametersWithIV(key, new byte[16]); ctrEngine.init(false, params); int i = 0; byte[] out = new byte[cipher.length]; while (i < cipher.length) { ctrEngine.processBlock(cipher, i, out, i); i += engine.getBlockSize(); if (cipher.length - i < engine.getBlockSize()) break; } // process left bytes if (cipher.length - i > 0) { byte[] tmpBlock = new byte[16]; System.arraycopy(cipher, i, tmpBlock, 0, cipher.length - i); ctrEngine.processBlock(tmpBlock, 0, tmpBlock, 0); System.arraycopy(tmpBlock, 0, out, i, cipher.length - i); } return out; }
Example 4
Source File: ECKey.java From tron-wallet-android with Apache License 2.0 | 5 votes |
/** * Decrypt cipher by AES in SIC(also know as CTR) mode * * @param cipher -proper cipher * @return decrypted cipher, equal length to the cipher. * @deprecated should not use EC private scalar value as an AES key */ public byte[] decryptAES(byte[] cipher) { if (privKey == null) { throw new MissingPrivateKeyException(); } if (!(privKey instanceof BCECPrivateKey)) { throw new UnsupportedOperationException("Cannot use the private " + "key as an AES key"); } AESFastEngine engine = new AESFastEngine(); SICBlockCipher ctrEngine = new SICBlockCipher(engine); KeyParameter key = new KeyParameter(BigIntegers.asUnsignedByteArray(( (BCECPrivateKey) privKey).getD())); ParametersWithIV params = new ParametersWithIV(key, new byte[16]); ctrEngine.init(false, params); int i = 0; byte[] out = new byte[cipher.length]; while (i < cipher.length) { ctrEngine.processBlock(cipher, i, out, i); i += engine.getBlockSize(); if (cipher.length - i < engine.getBlockSize()) { break; } } // process left bytes if (cipher.length - i > 0) { byte[] tmpBlock = new byte[16]; System.arraycopy(cipher, i, tmpBlock, 0, cipher.length - i); ctrEngine.processBlock(tmpBlock, 0, tmpBlock, 0); System.arraycopy(tmpBlock, 0, out, i, cipher.length - i); } return out; }