/** @throws IllegalArgumentException if data is not the legal number of bytes (but null is ok) */ public SimpleDataStructure(byte data[]) { setData(data); }
/** * Sets the data. * @param data 32 bytes, or null * @throws IllegalArgumentException if data is not the legal number of bytes (but null is ok) * @throws RuntimeException if data already set. */ @Override public void setData(byte[] data) { super.setData(data); }
/** @throws IllegalArgumentException if data is not 32 bytes (null is ok) */ @Override public void setData(byte[] data) { super.setData(data); _base64ed = null; _cachedHashCode = super.hashCode(); }
@Override public void setData(byte[] data) { super.setData(data); _cachedHashCode = SipHash.hashCode(data); }
/** @throws IllegalArgumentException if data is not 20 bytes (null is ok) */ @Override public void setData(byte[] data) { super.setData(data); _cachedHashCode = super.hashCode(); }
/** * DSA-SHA1 only. * * Same as above but different return type * @since 0.8.7 */ public SimpleDataStructure[] generateSigningKeys() { SimpleDataStructure[] keys = new SimpleDataStructure[2]; BigInteger x = null; // make sure the random key is less than the DSA q and greater than zero do { x = new NativeBigInteger(160, _context.random()); } while (x.compareTo(CryptoConstants.dsaq) >= 0 || x.equals(BigInteger.ZERO)); BigInteger y = CryptoConstants.dsag.modPow(x, CryptoConstants.dsap); keys[0] = new SigningPublicKey(); keys[1] = new SigningPrivateKey(); try { keys[0].setData(SigUtil.rectify(y, SigningPublicKey.KEYSIZE_BYTES)); keys[1].setData(SigUtil.rectify(x, SigningPrivateKey.KEYSIZE_BYTES)); } catch (InvalidKeyException ike) { throw new IllegalStateException(ike); } return keys; }
/** * Overridden for efficiency. * Does the same thing as setData() but null not allowed. * @param data non-null * @throws DataFormatException if null or wrong length * @throws RuntimeException if data already set. */ @Override public void fromByteArray(byte data[]) throws DataFormatException { if (data == null) throw new DataFormatException("Null data passed in"); if (data.length != length()) throw new DataFormatException("Bad data length: " + data.length + "; required: " + length()); // call setData() instead of _data = data in case overridden setData(data); }
/** * Same as above but different return type * @since 0.8.7 */ public SimpleDataStructure[] generatePKIKeys() { BigInteger a = new NativeBigInteger(getElGamalExponentSize(), _context.random()); BigInteger aalpha = CryptoConstants.elgg.modPow(a, CryptoConstants.elgp); SimpleDataStructure[] keys = new SimpleDataStructure[2]; keys[0] = new PublicKey(); keys[1] = new PrivateKey(); // bigInteger.toByteArray returns SIGNED integers, but since they'return positive, // signed two's complement is the same as unsigned try { keys[0].setData(SigUtil.rectify(aalpha, PublicKey.KEYSIZE_BYTES)); keys[1].setData(SigUtil.rectify(a, PrivateKey.KEYSIZE_BYTES)); } catch (InvalidKeyException ike) { throw new IllegalArgumentException(ike); } return keys; }
throw new IOException(avail + " bytes data after sig"); SimpleDataStructure hash = _sigType.getHashInstance(); hash.setData(sha);
byte[] sha = md.digest(); SimpleDataStructure hash = type.getHashInstance(); hash.setData(sha); long start = System.nanoTime(); Signature sig = DSAEngine.getInstance().sign(src, privkey);
/** * Sets the data. * @throws DataFormatException if decoded data is not the legal number of bytes or on decoding error * @throws RuntimeException if data already set. */ @Override public void fromBase64(String data) throws DataFormatException { if (data == null) throw new DataFormatException("Null data passed in"); byte[] d = Base64.decode(data); if (d == null) throw new DataFormatException("Bad Base64 encoded data"); if (d.length != length()) throw new DataFormatException("Bad decoded data length, expected " + length() + " got " + d.length); // call setData() instead of _data = data in case overridden setData(d); }
out.on(false); SimpleDataStructure hash = sigType.getHashInstance(); hash.setData(sha); Signature signature = _context.dsa().sign(hash, privkey, sigType); if (signature == null)
hash.setData(digest.digest()); _isValid = DSAEngine.getInstance().verifySignature(_signature, hash, _identity.getSigningPublicKey()); _validated = true;