public static byte[] toByteArray(int in,int outSize) { byte[] out = new byte[outSize]; byte[] intArray = toByteArray(in); for( int i=0; i<intArray.length && i<outSize; i++ ) { out[i] = intArray[i]; } return out; }
public static byte[] toByteArray(int in,int outSize) { byte[] out = new byte[outSize]; byte[] intArray = toByteArray(in); for( int i=0; i<intArray.length && i<outSize; i++ ) { out[i] = intArray[i]; } return out; }
protected void initDirOffsetPosAndComment() throws IOException { // zip files without a comment contain the offset/position of the central directory at this fixed position this.dirOffsetPos = zipFile.length() - 6; final int dirOffset = raFile.readInt( this.dirOffsetPos - 16 ); if( dirOffset!=ENDSIG ) { // if a comment is present, search the ENDSIG constant, starting at the end of the zip file byte[] endsig = ByteArrayHelper.toByteArray((int)ZipConstants.ENDSIG); long endsigPos = raFile.lastPosOf(endsig); if( endsigPos==-1 ) { throw new ZipException("expected ENDSIC not found (marks the beginning of the central directory at end of the zip file)"); } else { this.dirOffsetPos = endsigPos+16; short commentLength = raFile.readShort( this.dirOffsetPos + 4 ); this.comment = new String( raFile.readByteArray( this.dirOffsetPos+6, commentLength ) ); } } }
protected void initDirOffsetPosAndComment() throws IOException { // zip files without a comment contain the offset/position of the central directory at this fixed position this.dirOffsetPos = zipFile.length() - 6; final int dirOffset = raFile.readInt( this.dirOffsetPos - 16 ); if( dirOffset!=ENDSIG ) { // if a comment is present, search the ENDSIG constant, starting at the end of the zip file byte[] endsig = ByteArrayHelper.toByteArray((int)ZipConstants.ENDSIG); long endsigPos = raFile.lastPosOf(endsig); if( endsigPos==-1 ) { throw new ZipException("expected ENDSIC not found (marks the beginning of the central directory at end of the zip file)"); } else { this.dirOffsetPos = endsigPos+16; short commentLength = raFile.readShort( this.dirOffsetPos + 4 ); this.comment = new String( raFile.readByteArray( this.dirOffsetPos+6, commentLength ) ); } } }
/** * encrypt 16 bytes (AES standard block size) or less * starting at "pos" within "in" byte[] */ protected void encryptBlock( byte[] in, int pos, int length ) { byte[] encryptedIn = new byte[blockSize]; byte[] ivBytes = ByteArrayHelper.toByteArray( nonce++, 16 ); ParametersWithIV ivParams = new ParametersWithIV(cipherParameters, ivBytes); aesCipher.init( true, ivParams ); int remainingCount = length-pos; if( remainingCount>=blockSize ) { aesCipher.processBlock( in, pos, encryptedIn, 0 ); System.arraycopy( encryptedIn, 0, in, pos, blockSize ); mac.update( encryptedIn, 0, blockSize ); } else { byte[] extendedIn = new byte[blockSize]; System.arraycopy( in, pos, extendedIn, 0, remainingCount ); aesCipher.processBlock( extendedIn, 0, encryptedIn, 0 ); System.arraycopy( encryptedIn, 0, in, pos, remainingCount ); mac.update( encryptedIn, 0, remainingCount ); } }
/** * encrypt 16 bytes (AES standard block size) or less * starting at "pos" within "in" byte[] */ protected void encryptBlock( byte[] in, int pos, int length ) { byte[] encryptedIn = new byte[blockSize]; byte[] ivBytes = ByteArrayHelper.toByteArray( nonce++, 16 ); ParametersWithIV ivParams = new ParametersWithIV(cipherParameters, ivBytes); aesCipher.init( true, ivParams ); int remainingCount = length-pos; if( remainingCount>=blockSize ) { aesCipher.processBlock( in, pos, encryptedIn, 0 ); System.arraycopy( encryptedIn, 0, in, pos, blockSize ); mac.update( encryptedIn, 0, blockSize ); } else { byte[] extendedIn = new byte[blockSize]; System.arraycopy( in, pos, extendedIn, 0, remainingCount ); aesCipher.processBlock( extendedIn, 0, encryptedIn, 0 ); System.arraycopy( encryptedIn, 0, in, pos, remainingCount ); mac.update( encryptedIn, 0, remainingCount ); } }
/** * encrypt 16 bytes (AES standard block size) or less * starting at "pos" within "in" byte[] */ protected void decryptBlock( byte[] in, int pos, int length ) { byte[] decryptedIn = new byte[blockSize]; byte[] ivBytes = ByteArrayHelper.toByteArray( nonce++, 16 ); ParametersWithIV ivParams = new ParametersWithIV(cipherParameters, ivBytes); aesCipher.init( false, ivParams ); int remainingCount = length-pos; if( remainingCount>=blockSize ) { mac.update( in, pos, blockSize ); aesCipher.processBlock( in, pos, decryptedIn, 0 ); System.arraycopy( decryptedIn, 0, in, pos, blockSize ); } else { mac.update( in, pos, remainingCount ); byte[] extendedIn = new byte[blockSize]; System.arraycopy( in, pos, extendedIn, 0, remainingCount ); aesCipher.processBlock( extendedIn, 0, decryptedIn, 0 ); System.arraycopy( decryptedIn, 0, in, pos, remainingCount ); } }
/** * encrypt 16 bytes (AES standard block size) or less * starting at "pos" within "in" byte[] */ protected void decryptBlock( byte[] in, int pos, int length ) { byte[] decryptedIn = new byte[blockSize]; byte[] ivBytes = ByteArrayHelper.toByteArray( nonce++, 16 ); ParametersWithIV ivParams = new ParametersWithIV(cipherParameters, ivBytes); aesCipher.init( false, ivParams ); int remainingCount = length-pos; if( remainingCount>=blockSize ) { mac.update( in, pos, blockSize ); aesCipher.processBlock( in, pos, decryptedIn, 0 ); System.arraycopy( decryptedIn, 0, in, pos, blockSize ); } else { mac.update( in, pos, remainingCount ); byte[] extendedIn = new byte[blockSize]; System.arraycopy( in, pos, extendedIn, 0, remainingCount ); aesCipher.processBlock( extendedIn, 0, decryptedIn, 0 ); System.arraycopy( decryptedIn, 0, in, pos, remainingCount ); } }