本文整理汇总了Java中org.spongycastle.crypto.DataLengthException类的典型用法代码示例。如果您正苦于以下问题:Java DataLengthException类的具体用法?Java DataLengthException怎么用?Java DataLengthException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DataLengthException类属于org.spongycastle.crypto包,在下文中一共展示了DataLengthException类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateBytes
import org.spongycastle.crypto.DataLengthException; //导入依赖的package包/类
public int generateBytes(byte[] out, int outOff, int len) throws DataLengthException, IllegalArgumentException {
if(out.length - len < outOff) {
throw new DataLengthException("output buffer too small");
} else {
byte[] hashBuf = new byte[this.hLen];
byte[] C = new byte[4];
int counter = 0;
int hashCounter = counterStart;
this.digest.reset();
if(len > this.hLen) {
do {
this.ItoOSP(hashCounter++, C);
this.digest.update(this.seed, 0, this.seed.length);
this.digest.update(C, 0, C.length);
this.digest.doFinal(hashBuf, 0);
System.arraycopy(hashBuf, 0, out, outOff + counter * this.hLen, this.hLen);
++counter;
} while(counter < len / this.hLen);
}
if(counter * this.hLen < len) {
this.ItoOSP(hashCounter, C);
this.digest.update(this.seed, 0, this.seed.length);
this.digest.update(C, 0, C.length);
this.digest.doFinal(hashBuf, 0);
System.arraycopy(hashBuf, 0, out, outOff + counter * this.hLen, len - counter * this.hLen);
}
return len;
}
}
示例2: generateBytes
import org.spongycastle.crypto.DataLengthException; //导入依赖的package包/类
public int generateBytes(byte[] out, int outOff, int len) throws DataLengthException, IllegalArgumentException {
if(out.length - len < outOff) {
throw new DataLengthException("output buffer too small");
} else {
byte[] hashBuf = new byte[this.hLen];
byte[] c = new byte[4];
int counter = 0;
int hashCounter = counterStart;
this.digest.reset();
if(len > this.hLen) {
do {
this.itoosp(hashCounter++, c);
this.digest.update(this.seed, 0, this.seed.length);
this.digest.update(c, 0, c.length);
this.digest.doFinal(hashBuf, 0);
System.arraycopy(hashBuf, 0, out, outOff + counter * this.hLen, this.hLen);
++counter;
} while(counter < len / this.hLen);
}
if(counter * this.hLen < len) {
this.itoosp(hashCounter, c);
this.digest.update(this.seed, 0, this.seed.length);
this.digest.update(c, 0, c.length);
this.digest.doFinal(hashBuf, 0);
System.arraycopy(hashBuf, 0, out, outOff + counter * this.hLen, len - counter * this.hLen);
}
return len;
}
}
示例3: generateBytes
import org.spongycastle.crypto.DataLengthException; //导入依赖的package包/类
/**
* fill len bytes of the output buffer with bytes generated from the
* derivation function.
*
* @throws IllegalArgumentException
* if the size of the request will cause an overflow.
* @throws DataLengthException
* if the out buffer is too small.
*/
public int generateBytes(byte[] out, int outOff, int len) throws DataLengthException,
IllegalArgumentException
{
if ((out.length - len) < outOff)
{
throw new DataLengthException("output buffer too small");
}
long oBytes = len;
int outLen = digest.getDigestSize();
//
// this is at odds with the standard implementation, the
// maximum value should be hBits * (2^32 - 1) where hBits
// is the digest output size in bits. We can't have an
// array with a long index at the moment...
//
if (oBytes > ((2L << 32) - 1))
{
throw new IllegalArgumentException("Output length too large");
}
int cThreshold = (int)((oBytes + outLen - 1) / outLen);
byte[] dig = new byte[digest.getDigestSize()];
byte[] C = new byte[4];
Pack.intToBigEndian(counterStart, C, 0);
int counterBase = counterStart & ~0xFF;
for (int i = 0; i < cThreshold; i++)
{
digest.update(C, 0, C.length);
digest.update(shared, 0, shared.length);
if (iv != null)
{
digest.update(iv, 0, iv.length);
}
digest.doFinal(dig, 0);
if (len > outLen)
{
System.arraycopy(dig, 0, out, outOff, outLen);
outOff += outLen;
len -= outLen;
}
else
{
System.arraycopy(dig, 0, out, outOff, len);
}
if (++C[3] == 0)
{
counterBase += 0x100;
Pack.intToBigEndian(counterBase, C, 0);
}
}
digest.reset();
return (int)oBytes;
}
示例4: process
import org.spongycastle.crypto.DataLengthException; //导入依赖的package包/类
@Override
public int process(byte[] input, int inputOff, int len, byte[] output,
int outputOff) throws GeneralSecurityException {
if (!encrypting && len < MAC_LENGTH)
throw new GeneralSecurityException("Invalid MAC");
try {
// Generate the Poly1305 subkey from an empty array
byte[] zero = new byte[SUBKEY_LENGTH];
byte[] subKey = new byte[SUBKEY_LENGTH];
xSalsa20Engine.processBytes(zero, 0, SUBKEY_LENGTH, subKey, 0);
// Reverse the order of the Poly130 subkey
//
// NaCl and libsodium use the first 32 bytes of XSalsa20 as the
// subkey for crypto_onetimeauth_poly1305, which interprets it
// as r[0] ... r[15], k[0] ... k[15]. See section 9 of the NaCl
// paper (http://cr.yp.to/highspeed/naclcrypto-20090310.pdf),
// where the XSalsa20 output is defined as (r, s, t, ...).
//
// BC's Poly1305 implementation interprets the subkey as
// k[0] ... k[15], r[0] ... r[15] (per poly1305_aes_clamp in
// the reference implementation).
//
// To be NaCl-compatible, we reverse the subkey.
System.arraycopy(subKey, 0, zero, 0, SUBKEY_LENGTH / 2);
System.arraycopy(subKey, SUBKEY_LENGTH / 2, subKey, 0,
SUBKEY_LENGTH / 2);
System.arraycopy(zero, 0, subKey, SUBKEY_LENGTH / 2,
SUBKEY_LENGTH / 2);
// Now we can clamp the correct part of the subkey
Poly1305KeyGenerator.clamp(subKey);
// Initialize Poly1305 with the subkey
KeyParameter k = new KeyParameter(subKey);
poly1305.init(k);
// If we are decrypting, verify the MAC
if (!encrypting) {
byte[] mac = new byte[MAC_LENGTH];
poly1305.update(input, inputOff + MAC_LENGTH, len - MAC_LENGTH);
poly1305.doFinal(mac, 0);
// Constant-time comparison
int cmp = 0;
for (int i = 0; i < MAC_LENGTH; i++)
cmp |= mac[i] ^ input[inputOff + i];
if (cmp != 0)
throw new GeneralSecurityException("Invalid MAC");
}
// Apply or invert the stream encryption
int processed = xSalsa20Engine.processBytes(
input, encrypting ? inputOff : inputOff + MAC_LENGTH,
encrypting ? len : len - MAC_LENGTH,
output, encrypting ? outputOff + MAC_LENGTH : outputOff);
// If we are encrypting, generate the MAC
if (encrypting) {
poly1305.update(output, outputOff + MAC_LENGTH, len);
poly1305.doFinal(output, outputOff);
}
return encrypting ? processed + MAC_LENGTH : processed;
} catch (DataLengthException e) {
throw new GeneralSecurityException(e.getMessage());
}
}
示例5: generateBytes
import org.spongycastle.crypto.DataLengthException; //导入依赖的package包/类
/**
* fill len bytes of the output buffer with bytes generated from the
* derivation function.
*
* @throws IllegalArgumentException
* if the size of the request will cause an overflow.
* @throws DataLengthException
* if the out buffer is too small.
*/
public int generateBytes(byte[] out, int outOff, int len) throws DataLengthException,
IllegalArgumentException
{
if ((out.length - len) < outOff)
{
throw new DataLengthException("output buffer too small");
}
long oBytes = len;
int outLen = digest.getDigestSize();
//
// this is at odds with the standard implementation, the
// maximum value should be hBits * (2^32 - 1) where hBits
// is the digest output size in bits. We can't have an
// array with a long index at the moment...
//
if (oBytes > ((2L << 32) - 1))
{
throw new IllegalArgumentException("Output length too large");
}
int cThreshold = (int)((oBytes + outLen - 1) / outLen);
byte[] dig = new byte[digest.getDigestSize()];
byte[] c = new byte[4];
Pack.intToBigEndian(counterStart, c, 0);
int counterBase = counterStart & ~0xFF;
for (int i = 0; i < cThreshold; i++)
{
digest.update(c, 0, c.length);
digest.update(shared, 0, shared.length);
if (iv != null)
{
digest.update(iv, 0, iv.length);
}
digest.doFinal(dig, 0);
if (len > outLen)
{
System.arraycopy(dig, 0, out, outOff, outLen);
outOff += outLen;
len -= outLen;
}
else
{
System.arraycopy(dig, 0, out, outOff, len);
}
if (++c[3] == 0)
{
counterBase += 0x100;
Pack.intToBigEndian(counterBase, c, 0);
}
}
digest.reset();
return (int)oBytes;
}
示例6: encryptNoPadding
import org.spongycastle.crypto.DataLengthException; //导入依赖的package包/类
public static byte[] encryptNoPadding(byte[] key, byte[] input) throws DataLengthException, InvalidCipherTextException {
bbc = new BufferedBlockCipher(AESCipher);
AESSpongeyCastle.key = new KeyParameter(key);
return processingNoPadding(input, true);
}
示例7: decryptNoPadding
import org.spongycastle.crypto.DataLengthException; //导入依赖的package包/类
public static byte[] decryptNoPadding(byte[] key, byte[] input) throws DataLengthException, InvalidCipherTextException {
bbc = new BufferedBlockCipher(AESCipher);
AESSpongeyCastle.key = new KeyParameter(key);
return processingNoPadding(input, false);
}
示例8: encrypt
import org.spongycastle.crypto.DataLengthException; //导入依赖的package包/类
public static byte[] encrypt(byte[] key, byte[] input) throws DataLengthException, InvalidCipherTextException {
pbbc = new PaddedBufferedBlockCipher(AESCipher, new PKCS7Padding());
AESSpongeyCastle.key = new KeyParameter(key);
return processing(input, true);
}
示例9: decrypt
import org.spongycastle.crypto.DataLengthException; //导入依赖的package包/类
public static byte[] decrypt(byte[] key, byte[] input) throws DataLengthException, InvalidCipherTextException {
pbbc = new PaddedBufferedBlockCipher(AESCipher, new PKCS7Padding());
AESSpongeyCastle.key = new KeyParameter(key);
return processing(input, false);
}
示例10: encrypt
import org.spongycastle.crypto.DataLengthException; //导入依赖的package包/类
public static byte[] encrypt(byte[] key, byte[] input) throws DataLengthException, InvalidCipherTextException {
pbbc = new PaddedBufferedBlockCipher(ThreefishCipher, new PKCS7Padding());
ThreefishSpongeyCastle.key = new KeyParameter(key);
return processing(input, true);
}
示例11: decrypt
import org.spongycastle.crypto.DataLengthException; //导入依赖的package包/类
public static byte[] decrypt(byte[] key, byte[] input) throws DataLengthException, InvalidCipherTextException {
pbbc = new PaddedBufferedBlockCipher(ThreefishCipher, new PKCS7Padding());
ThreefishSpongeyCastle.key = new KeyParameter(key);
return processing(input, false);
}
示例12: processingNoPadding
import org.spongycastle.crypto.DataLengthException; //导入依赖的package包/类
private static byte[] processingNoPadding(byte[] input, boolean encrypt)
throws DataLengthException, InvalidCipherTextException {
bbc.init(encrypt, key);
byte[] output = new byte[bbc.getOutputSize(input.length)];
int bytesWrittenOut = bbc.processBytes(
input, 0, input.length, output, 0);
bbc.doFinal(output, bytesWrittenOut);
return output;
}
示例13: processing
import org.spongycastle.crypto.DataLengthException; //导入依赖的package包/类
private static byte[] processing(byte[] input, boolean encrypt)
throws DataLengthException, InvalidCipherTextException {
pbbc.init(encrypt, key);
byte[] output = new byte[pbbc.getOutputSize(input.length)];
int bytesWrittenOut = pbbc.processBytes(
input, 0, input.length, output, 0);
pbbc.doFinal(output, bytesWrittenOut);
return output;
}