本文整理汇总了Java中org.bouncycastle.crypto.engines.AESWrapEngine类的典型用法代码示例。如果您正苦于以下问题:Java AESWrapEngine类的具体用法?Java AESWrapEngine怎么用?Java AESWrapEngine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AESWrapEngine类属于org.bouncycastle.crypto.engines包,在下文中一共展示了AESWrapEngine类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: wrap
import org.bouncycastle.crypto.engines.AESWrapEngine; //导入依赖的package包/类
public static byte[] wrap(byte[] key, byte[] data) {
AESWrapEngine engine = new AESWrapEngine();
KeyParameter params = new KeyParameter(key);
engine.init(true, params);
PKCS7Padding padding = new PKCS7Padding();
byte[] unpadded = data;
//
// Add padding
//
byte[] padded = new byte[unpadded.length + (8 - unpadded.length % 8)];
System.arraycopy(unpadded, 0, padded, 0, unpadded.length);
padding.addPadding(padded, unpadded.length);
//
// Wrap
//
byte[] encrypted = engine.wrap(padded, 0, padded.length);
return encrypted;
}
开发者ID:cityzendata,项目名称:warp10-platform,代码行数:24,代码来源:CryptoUtils.java
示例2: unwrap
import org.bouncycastle.crypto.engines.AESWrapEngine; //导入依赖的package包/类
public static byte[] unwrap(byte[] key, byte[] data) {
//
// Decrypt the encrypted data
//
AESWrapEngine engine = new AESWrapEngine();
CipherParameters params = new KeyParameter(key);
engine.init(false, params);
try {
byte[] decrypted = engine.unwrap(data, 0, data.length);
//
// Unpad the decrypted data
//
PKCS7Padding padding = new PKCS7Padding();
int padcount = padding.padCount(decrypted);
//
// Remove padding
//
decrypted = Arrays.copyOfRange(decrypted, 0, decrypted.length - padcount);
return decrypted;
} catch (InvalidCipherTextException icte) {
return null;
}
}
开发者ID:cityzendata,项目名称:warp10-platform,代码行数:30,代码来源:CryptoUtils.java
示例3: AES_KeyWrap_Encrypt
import org.bouncycastle.crypto.engines.AESWrapEngine; //导入依赖的package包/类
private byte[] AES_KeyWrap_Encrypt(AlgorithmID alg, byte[] rgbKey) throws CoseException
{
if (rgbKey.length != alg.getKeySize() / 8) throw new CoseException("Key is not the correct size");
AESWrapEngine foo = new AESWrapEngine();
KeyParameter parameters = new KeyParameter(rgbKey);
foo.init(true, parameters);
return foo.wrap(rgbContent, 0, rgbContent.length);
}
开发者ID:cose-wg,项目名称:COSE-JAVA,代码行数:10,代码来源:Recipient.java
示例4: AES_KeyWrap_Decrypt
import org.bouncycastle.crypto.engines.AESWrapEngine; //导入依赖的package包/类
private byte[] AES_KeyWrap_Decrypt(AlgorithmID alg, byte[] rgbKey) throws CoseException, InvalidCipherTextException
{
if (rgbKey.length != alg.getKeySize() / 8) throw new CoseException("Key is not the correct size");
AESWrapEngine foo = new AESWrapEngine();
KeyParameter parameters = new KeyParameter(rgbKey);
foo.init(false, parameters);
return foo.unwrap(rgbEncrypted, 0, rgbEncrypted.length);
}
开发者ID:cose-wg,项目名称:COSE-JAVA,代码行数:10,代码来源:Recipient.java
示例5: KeyWrap
import org.bouncycastle.crypto.engines.AESWrapEngine; //导入依赖的package包/类
public static byte[] KeyWrap(Transformation transformation, byte[] symmetricKey, byte[] cek) {
AESWrapEngine engine = new AESWrapEngine();
CipherParameters param = new KeyParameter(
new SecretKeySpec(symmetricKey, transformation.getAlgorithm()).getEncoded());
engine.init(true, param);
return engine.wrap(cek, 0, cek.length);
}
开发者ID:SKplanet,项目名称:syruppay-java,代码行数:8,代码来源:CryptoUtils.java
示例6: keyUnwrap
import org.bouncycastle.crypto.engines.AESWrapEngine; //导入依赖的package包/类
public static byte[] keyUnwrap(Transformation transformation, byte[] symmetricKey, byte[] cek) throws Exception {
AESWrapEngine engine = new AESWrapEngine();
CipherParameters param = new KeyParameter(
new SecretKeySpec(symmetricKey, transformation.getAlgorithm()).getEncoded());
engine.init(false, param);
return engine.unwrap(cek, 0, cek.length);
}
开发者ID:SKplanet,项目名称:syruppay-java,代码行数:8,代码来源:CryptoUtils.java
示例7: BcAESSymmetricKeyWrapper
import org.bouncycastle.crypto.engines.AESWrapEngine; //导入依赖的package包/类
public BcAESSymmetricKeyWrapper(KeyParameter wrappingKey)
{
super(AESUtil.determineKeyEncAlg(wrappingKey), new AESWrapEngine(), wrappingKey);
}
开发者ID:Appdome,项目名称:ipack,代码行数:5,代码来源:BcAESSymmetricKeyWrapper.java
示例8: BcAESSymmetricKeyUnwrapper
import org.bouncycastle.crypto.engines.AESWrapEngine; //导入依赖的package包/类
public BcAESSymmetricKeyUnwrapper(KeyParameter wrappingKey)
{
super(AESUtil.determineKeyEncAlg(wrappingKey), new AESWrapEngine(), wrappingKey);
}
开发者ID:Appdome,项目名称:ipack,代码行数:5,代码来源:BcAESSymmetricKeyUnwrapper.java
示例9: Wrap
import org.bouncycastle.crypto.engines.AESWrapEngine; //导入依赖的package包/类
public Wrap()
{
super(new AESWrapEngine());
}
开发者ID:Appdome,项目名称:ipack,代码行数:5,代码来源:AES.java
示例10: getBytes
import org.bouncycastle.crypto.engines.AESWrapEngine; //导入依赖的package包/类
/**
* Return the bytes currently in this encoder.
* If 'wrappingKey' is non null, encrypt the bytes prior to returning them.
*
* @return The (possibly encrypted bytes) or null if an exception is raised
* while encrypting.
*
*/
public byte[] getBytes() {
if (null == this.wrappingKey) {
return this.stream.toByteArray();
} else {
AESWrapEngine engine = new AESWrapEngine();
KeyParameter params = new KeyParameter(this.wrappingKey);
engine.init(true, params);
PKCS7Padding padding = new PKCS7Padding();
byte[] unpadded = this.stream.toByteArray();
//
// Add padding
//
byte[] padded = new byte[unpadded.length + (8 - unpadded.length % 8)];
System.arraycopy(unpadded, 0, padded, 0, unpadded.length);
padding.addPadding(padded, unpadded.length);
//
// Wrap
//
byte[] encrypted = engine.wrap(padded, 0, padded.length);
//
// Add 0x0 flag and encrypted data size
//
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
baos.write(GTSEncoder.FLAGS_ENCRYPTED);
baos.write(Varint.encodeUnsignedLong(encrypted.length));
baos.write(encrypted);
return baos.toByteArray();
} catch (IOException ioe) {
return null;
}
}
}
开发者ID:cityzendata,项目名称:warp10-platform,代码行数:49,代码来源:GTSEncoder.java
示例11: testAddValue_encrypted
import org.bouncycastle.crypto.engines.AESWrapEngine; //导入依赖的package包/类
@Test
public void testAddValue_encrypted() throws Exception {
long now = System.currentTimeMillis() * 1000L;
byte[] key = new byte[32];
GTSEncoder encoder = new GTSEncoder(now - 1000000L, key);
encoder.addValue(now, GeoTimeSerie.NO_LOCATION, GeoTimeSerie.NO_ELEVATION, 1L);
encoder.addValue(now + 1000000L, GeoTimeSerie.NO_LOCATION, GeoTimeSerie.NO_ELEVATION, 2L);
byte[] encrypted = encoder.getBytes();
Assert.assertEquals(GTSEncoder.FLAGS_ENCRYPTED, encrypted[0] & GTSEncoder.FLAGS_MASK_ENCRYPTED);
Assert.assertEquals(26, encrypted.length);
//
// Now check that we can decrypt the payload
// We can't use n offset different than 0 in unwrap due to BJA-461
// so we have to copy the data prior to decrypting it.
//
AESWrapEngine engine = new AESWrapEngine();
KeyParameter params = new KeyParameter(key);
engine.init(false, params);
byte[] enc = new byte[24];
System.arraycopy(encrypted, 2, enc, 0, 24);
byte[] decrypted = engine.unwrap(enc, 0, 24);
//
// Now decode the decrypted data
//
PKCS7Padding padding = new PKCS7Padding();
GTSDecoder decoder = new GTSDecoder(now - 1000000L, ByteBuffer.wrap(decrypted, 0, decrypted.length - padding.padCount(decrypted)));
decoder.next();
Assert.assertEquals(now, decoder.getTimestamp());
Assert.assertEquals(GeoTimeSerie.NO_LOCATION, decoder.getLocation());
Assert.assertEquals(GeoTimeSerie.NO_ELEVATION, decoder.getElevation());
Assert.assertEquals(1L, decoder.getValue());
decoder.next();
Assert.assertEquals(now + 1000000L, decoder.getTimestamp());
Assert.assertEquals(GeoTimeSerie.NO_LOCATION, decoder.getLocation());
Assert.assertEquals(GeoTimeSerie.NO_ELEVATION, decoder.getElevation());
Assert.assertEquals(2L, decoder.getValue());
}
开发者ID:cityzendata,项目名称:warp10-platform,代码行数:48,代码来源:GTSEncoderTest.java
注:本文中的org.bouncycastle.crypto.engines.AESWrapEngine类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论