本文整理汇总了Java中org.spongycastle.crypto.modes.SICBlockCipher类的典型用法代码示例。如果您正苦于以下问题:Java SICBlockCipher类的具体用法?Java SICBlockCipher怎么用?Java SICBlockCipher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SICBlockCipher类属于org.spongycastle.crypto.modes包,在下文中一共展示了SICBlockCipher类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: decrypt
import org.spongycastle.crypto.modes.SICBlockCipher; //导入依赖的package包/类
public static byte[] decrypt(ECPoint ephem, BigInteger prv, byte[] IV, byte[] cipher, byte[] macData) throws InvalidCipherTextException {
AESFastEngine aesFastEngine = new AESFastEngine();
EthereumIESEngine iesEngine = new EthereumIESEngine(
new ECDHBasicAgreement(),
new ConcatKDFBytesGenerator(new SHA256Digest()),
new HMac(new SHA256Digest()),
new SHA256Digest(),
new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));
byte[] d = new byte[] {};
byte[] e = new byte[] {};
IESParameters p = new IESWithCipherParameters(d, e, KEY_SIZE, KEY_SIZE);
ParametersWithIV parametersWithIV =
new ParametersWithIV(p, IV);
iesEngine.init(false, new ECPrivateKeyParameters(prv, CURVE), new ECPublicKeyParameters(ephem, CURVE), parametersWithIV);
return iesEngine.processBlock(cipher, 0, cipher.length, macData);
}
开发者ID:talentchain,项目名称:talchain,代码行数:23,代码来源:ECIESCoder.java
示例2: makeIESEngine
import org.spongycastle.crypto.modes.SICBlockCipher; //导入依赖的package包/类
private static EthereumIESEngine makeIESEngine(boolean isEncrypt, ECPoint pub, BigInteger prv, byte[] IV) {
AESFastEngine aesFastEngine = new AESFastEngine();
EthereumIESEngine iesEngine = new EthereumIESEngine(
new ECDHBasicAgreement(),
new ConcatKDFBytesGenerator(new SHA256Digest()),
new HMac(new SHA256Digest()),
new SHA256Digest(),
new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));
byte[] d = new byte[] {};
byte[] e = new byte[] {};
IESParameters p = new IESWithCipherParameters(d, e, KEY_SIZE, KEY_SIZE);
ParametersWithIV parametersWithIV = new ParametersWithIV(p, IV);
iesEngine.init(isEncrypt, new ECPrivateKeyParameters(prv, CURVE), new ECPublicKeyParameters(pub, CURVE), parametersWithIV);
return iesEngine;
}
开发者ID:talentchain,项目名称:talchain,代码行数:21,代码来源:ECIESCoder.java
示例3: makeIESEngine
import org.spongycastle.crypto.modes.SICBlockCipher; //导入依赖的package包/类
private static EthereumIESEngine makeIESEngine(boolean isEncrypt, ECPoint pub, BigInteger prv, byte[] IV) {
AESFastEngine aesFastEngine = new AESFastEngine();
EthereumIESEngine iesEngine = new EthereumIESEngine(
new ECDHBasicAgreement(),
new ConcatKDFBytesGenerator(new SHA256Digest()),
new HMac(new SHA256Digest()),
new SHA256Digest(),
new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));
byte[] d = new byte[] {};
byte[] e = new byte[] {};
IESParameters p = new IESWithCipherParameters(d, e, KEY_SIZE, KEY_SIZE);
ParametersWithIV parametersWithIV = new ParametersWithIV(p, IV);
iesEngine.init(isEncrypt, new ECPrivateKeyParameters(prv, curve), new ECPublicKeyParameters(pub, curve), parametersWithIV);
return iesEngine;
}
开发者ID:talentchain,项目名称:talchain,代码行数:21,代码来源:ECIESTest.java
示例4: decrypt
import org.spongycastle.crypto.modes.SICBlockCipher; //导入依赖的package包/类
public static byte[] decrypt(ECPoint ephem, BigInteger prv, byte[] iv, byte[] cipher, byte[] macData) throws InvalidCipherTextException {
AESFastEngine aesFastEngine = new AESFastEngine();
EthereumIESEngine iesEngine = new EthereumIESEngine(
new ECDHBasicAgreement(),
new ConcatKDFBytesGenerator(new SHA256Digest()),
new HMac(new SHA256Digest()),
new SHA256Digest(),
new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));
byte[] d = new byte[] {};
byte[] e = new byte[] {};
IESParameters p = new IESWithCipherParameters(d, e, KEY_SIZE, KEY_SIZE);
ParametersWithIV parametersWithIV =
new ParametersWithIV(p, iv);
iesEngine.init(false, new ECPrivateKeyParameters(prv, CURVE), new ECPublicKeyParameters(ephem, CURVE), parametersWithIV);
return iesEngine.processBlock(cipher, 0, cipher.length, macData);
}
开发者ID:rsksmart,项目名称:rskj,代码行数:23,代码来源:ECIESCoder.java
示例5: makeIESEngine
import org.spongycastle.crypto.modes.SICBlockCipher; //导入依赖的package包/类
private static EthereumIESEngine makeIESEngine(boolean isEncrypt, ECPoint pub, BigInteger prv, byte[] iv) {
AESFastEngine aesFastEngine = new AESFastEngine();
EthereumIESEngine iesEngine = new EthereumIESEngine(
new ECDHBasicAgreement(),
new ConcatKDFBytesGenerator(new SHA256Digest()),
new HMac(new SHA256Digest()),
new SHA256Digest(),
new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));
byte[] d = new byte[] {};
byte[] e = new byte[] {};
IESParameters p = new IESWithCipherParameters(d, e, KEY_SIZE, KEY_SIZE);
ParametersWithIV parametersWithIV = new ParametersWithIV(p, iv);
iesEngine.init(isEncrypt, new ECPrivateKeyParameters(prv, CURVE), new ECPublicKeyParameters(pub, CURVE), parametersWithIV);
return iesEngine;
}
开发者ID:rsksmart,项目名称:rskj,代码行数:21,代码来源:ECIESCoder.java
示例6: aesDecrypt
import org.spongycastle.crypto.modes.SICBlockCipher; //导入依赖的package包/类
public byte[] aesDecrypt(byte[] key, byte[] ctr, byte[] b) throws OtrCryptoException {
AESFastEngine aesDec = new AESFastEngine();
SICBlockCipher sicAesDec = new SICBlockCipher(aesDec);
BufferedBlockCipher bufSicAesDec = new BufferedBlockCipher(sicAesDec);
// Create initial counter value 0.
if (ctr == null)
ctr = ZERO_CTR;
bufSicAesDec.init(false, new ParametersWithIV(new KeyParameter(key), ctr));
byte[] aesOutLwDec = new byte[b.length];
int done = bufSicAesDec.processBytes(b, 0, b.length, aesOutLwDec, 0);
try {
bufSicAesDec.doFinal(aesOutLwDec, done);
} catch (Exception e) {
throw new OtrCryptoException(e);
}
return aesOutLwDec;
}
开发者ID:zom,项目名称:Zom-Android,代码行数:21,代码来源:OtrCryptoEngineImpl.java
示例7: aesEncrypt
import org.spongycastle.crypto.modes.SICBlockCipher; //导入依赖的package包/类
public byte[] aesEncrypt(byte[] key, byte[] ctr, byte[] b) throws OtrCryptoException {
AESFastEngine aesEnc = new AESFastEngine();
SICBlockCipher sicAesEnc = new SICBlockCipher(aesEnc);
BufferedBlockCipher bufSicAesEnc = new BufferedBlockCipher(sicAesEnc);
// Create initial counter value 0.
if (ctr == null)
ctr = ZERO_CTR;
bufSicAesEnc.init(true, new ParametersWithIV(new KeyParameter(key), ctr));
byte[] aesOutLwEnc = new byte[b.length];
int done = bufSicAesEnc.processBytes(b, 0, b.length, aesOutLwEnc, 0);
try {
bufSicAesEnc.doFinal(aesOutLwEnc, done);
} catch (Exception e) {
throw new OtrCryptoException(e);
}
return aesOutLwEnc;
}
开发者ID:zom,项目名称:Zom-Android,代码行数:20,代码来源:OtrCryptoEngineImpl.java
示例8: decryptAES
import org.spongycastle.crypto.modes.SICBlockCipher; //导入依赖的package包/类
/**
* 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;
}
开发者ID:toshiapp,项目名称:toshi-headless-client,代码行数:45,代码来源:ECKey.java
示例9: FrameCodec
import org.spongycastle.crypto.modes.SICBlockCipher; //导入依赖的package包/类
public FrameCodec(EncryptionHandshake.Secrets secrets) {
this.mac = secrets.mac;
int blockSize = secrets.aes.length * 8;
enc = new SICBlockCipher(new AESFastEngine());
enc.init(true, new ParametersWithIV(new KeyParameter(secrets.aes), new byte[blockSize / 8]));
dec = new SICBlockCipher(new AESFastEngine());
dec.init(false, new ParametersWithIV(new KeyParameter(secrets.aes), new byte[blockSize / 8]));
egressMac = secrets.egressMac;
ingressMac = secrets.ingressMac;
}
开发者ID:talentchain,项目名称:talchain,代码行数:11,代码来源:FrameCodec.java
示例10: test11
import org.spongycastle.crypto.modes.SICBlockCipher; //导入依赖的package包/类
@Test // basic encryption/decryption
public void test11() throws Throwable {
byte[] keyBytes = HashUtil.sha3("...".getBytes());
log.info("key: {}", Hex.toHexString(keyBytes));
byte[] ivBytes = new byte[16];
byte[] payload = Hex.decode("22400891000000000000000000000000");
KeyParameter key = new KeyParameter(keyBytes);
ParametersWithIV params = new ParametersWithIV(key, new byte[16]);
AESFastEngine engine = new AESFastEngine();
SICBlockCipher ctrEngine = new SICBlockCipher(engine);
ctrEngine.init(true, params);
byte[] cipher = new byte[16];
ctrEngine.processBlock(payload, 0, cipher, 0);
log.info("cipher: {}", Hex.toHexString(cipher));
byte[] output = new byte[cipher.length];
ctrEngine.init(false, params);
ctrEngine.processBlock(cipher, 0, output, 0);
assertEquals(Hex.toHexString(output), Hex.toHexString(payload));
log.info("original: {}", Hex.toHexString(payload));
}
开发者ID:talentchain,项目名称:talchain,代码行数:30,代码来源:CryptoTest.java
示例11: test12
import org.spongycastle.crypto.modes.SICBlockCipher; //导入依赖的package包/类
@Test // big packet encryption
public void test12() throws Throwable {
AESFastEngine engine = new AESFastEngine();
SICBlockCipher ctrEngine = new SICBlockCipher(engine);
byte[] keyBytes = Hex.decode("a4627abc2a3c25315bff732cb22bc128f203912dd2a840f31e66efb27a47d2b1");
byte[] ivBytes = new byte[16];
byte[] payload = Hex.decode("0109efc76519b683d543db9d0991bcde99cc9a3d14b1d0ecb8e9f1f66f31558593d746eaa112891b04ef7126e1dce17c9ac92ebf39e010f0028b8ec699f56f5d0c0d00");
byte[] cipherText = Hex.decode("f9fab4e9dd9fc3e5d0d0d16da254a2ac24df81c076e3214e2c57da80a46e6ae4752f4b547889fa692b0997d74f36bb7c047100ba71045cb72cfafcc7f9a251762cdf8f");
KeyParameter key = new KeyParameter(keyBytes);
ParametersWithIV params = new ParametersWithIV(key, ivBytes);
ctrEngine.init(true, params);
byte[] in = payload;
byte[] out = new byte[in.length];
int i = 0;
while(i < in.length){
ctrEngine.processBlock(in, i, out, i);
i += engine.getBlockSize();
if (in.length - i < engine.getBlockSize())
break;
}
// process left bytes
if (in.length - i > 0){
byte[] tmpBlock = new byte[16];
System.arraycopy(in, i, tmpBlock, 0, in.length - i);
ctrEngine.processBlock(tmpBlock, 0, tmpBlock, 0);
System.arraycopy(tmpBlock, 0, out, i, in.length - i);
}
log.info("cipher: {}", Hex.toHexString(out));
assertEquals(Hex.toHexString(cipherText), Hex.toHexString(out));
}
开发者ID:talentchain,项目名称:talchain,代码行数:41,代码来源:CryptoTest.java
示例12: decryptAES
import org.spongycastle.crypto.modes.SICBlockCipher; //导入依赖的package包/类
/**
* Decrypt cipher by AES in SIC(also know as CTR) mode
*
* @param cipher -proper cipher
* @return decrypted cipher, equal length to the cipher.
*/
public byte[] decryptAES(byte[] cipher){
if (priv == null) {
throw new MissingPrivateKeyException();
}
AESFastEngine engine = new AESFastEngine();
SICBlockCipher ctrEngine = new SICBlockCipher(engine);
KeyParameter key = new KeyParameter(BigIntegers.asUnsignedByteArray(priv));
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;
}
开发者ID:rsksmart,项目名称:rskj,代码行数:42,代码来源:ECKey.java
示例13: test11
import org.spongycastle.crypto.modes.SICBlockCipher; //导入依赖的package包/类
@Test // basic encryption/decryption
public void test11() throws Throwable {
byte[] keyBytes = sha3("...".getBytes());
log.info("key: {}", Hex.toHexString(keyBytes));
byte[] ivBytes = new byte[16];
byte[] payload = Hex.decode("22400891000000000000000000000000");
KeyParameter key = new KeyParameter(keyBytes);
ParametersWithIV params = new ParametersWithIV(key, new byte[16]);
AESFastEngine engine = new AESFastEngine();
SICBlockCipher ctrEngine = new SICBlockCipher(engine);
ctrEngine.init(true, params);
byte[] cipher = new byte[16];
ctrEngine.processBlock(payload, 0, cipher, 0);
log.info("cipher: {}", Hex.toHexString(cipher));
byte[] output = new byte[cipher.length];
ctrEngine.init(false, params);
ctrEngine.processBlock(cipher, 0, output, 0);
assertEquals(Hex.toHexString(output), Hex.toHexString(payload));
log.info("original: {}", Hex.toHexString(payload));
}
开发者ID:rsksmart,项目名称:rskj,代码行数:30,代码来源:CryptoTest.java
示例14: createAes128CtrPkcs7PaddingCipher
import org.spongycastle.crypto.modes.SICBlockCipher; //导入依赖的package包/类
static PaddedBufferedBlockCipher createAes128CtrPkcs7PaddingCipher(
boolean encrypting,
byte[] iv,
byte[] key) {
AESEngine aes = new AESEngine();
SICBlockCipher aesCtr = new SICBlockCipher(aes);
PaddedBufferedBlockCipher aesCtrPkcs7 =
new PaddedBufferedBlockCipher(aesCtr, new PKCS7Padding());
aesCtrPkcs7.init(encrypting, new ParametersWithIV(new KeyParameter(key), iv));
return aesCtrPkcs7;
}
开发者ID:openid,项目名称:OpenYOLO-Android,代码行数:13,代码来源:IoUtil.java
示例15: decryptAES
import org.spongycastle.crypto.modes.SICBlockCipher; //导入依赖的package包/类
/**
* 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;
}
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:44,代码来源:ECKey.java
示例16: decryptAES
import org.spongycastle.crypto.modes.SICBlockCipher; //导入依赖的package包/类
/**
* Decrypt cipher by AES in SIC(also know as CTR) mode
*
* @param cipher
* -proper cipher
* @return decrypted cipher, equal length to the cipher.
*/
public byte[] decryptAES(byte[] cipher) {
if (priv == null)
throw new MissingPrivateKeyException();
AESFastEngine engine = new AESFastEngine();
SICBlockCipher ctrEngine = new SICBlockCipher(engine);
KeyParameter key = new KeyParameter(BigIntegers.asUnsignedByteArray(priv));
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;
}
开发者ID:cegeka,项目名称:tether,代码行数:40,代码来源:ECKey.java
示例17: IV
import org.spongycastle.crypto.modes.SICBlockCipher; //导入依赖的package包/类
@Test // ECIES_AES128_SHA256 + No Ephemeral Key + IV(all zeroes)
public void test14() throws Throwable{
AESFastEngine aesFastEngine = new AESFastEngine();
IESEngine iesEngine = new IESEngine(
new ECDHBasicAgreement(),
new KDF2BytesGenerator(new SHA256Digest()),
new HMac(new SHA256Digest()),
new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));
byte[] d = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
byte[] e = new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 };
IESParameters p = new IESWithCipherParameters(d, e, 64, 128);
ParametersWithIV parametersWithIV = new ParametersWithIV(p, new byte[16]);
ECKeyPairGenerator eGen = new ECKeyPairGenerator();
KeyGenerationParameters gParam = new ECKeyGenerationParameters(ECKey.CURVE, new SecureRandom());
eGen.init(gParam);
AsymmetricCipherKeyPair p1 = eGen.generateKeyPair();
AsymmetricCipherKeyPair p2 = eGen.generateKeyPair();
ECKeyGenerationParameters keygenParams = new ECKeyGenerationParameters(ECKey.CURVE, new SecureRandom());
ECKeyPairGenerator generator = new ECKeyPairGenerator();
generator.init(keygenParams);
ECKeyPairGenerator gen = new ECKeyPairGenerator();
gen.init(new ECKeyGenerationParameters(ECKey.CURVE, new SecureRandom()));
iesEngine.init(true, p1.getPrivate(), p2.getPublic(), parametersWithIV);
byte[] message = Hex.decode("010101");
log.info("payload: {}", Hex.toHexString(message));
byte[] cipher = iesEngine.processBlock(message, 0, message.length);
log.info("cipher: {}", Hex.toHexString(cipher));
IESEngine decryptorIES_Engine = new IESEngine(
new ECDHBasicAgreement(),
new KDF2BytesGenerator (new SHA256Digest()),
new HMac(new SHA256Digest()),
new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));
decryptorIES_Engine.init(false, p2.getPrivate(), p1.getPublic(), parametersWithIV);
byte[] orig = decryptorIES_Engine.processBlock(cipher, 0, cipher.length);
log.info("orig: " + Hex.toHexString(orig));
}
开发者ID:talentchain,项目名称:talchain,代码行数:58,代码来源:CryptoTest.java
注:本文中的org.spongycastle.crypto.modes.SICBlockCipher类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论