/** * Initialise the cipher and, possibly, the initialisation vector (IV). * If an IV isn't passed as part of the parameter, the IV will be all zeros. * * @param forEncryption if true the cipher is initialised for * encryption, if false for decryption. * @param param the key and other data required by the cipher. * @exception IllegalArgumentException if the params argument is * inappropriate. */ public void init( bool encrypting, CipherParameters parameters) //throws IllegalArgumentException { this.encrypting = encrypting; if (typeof(ParametersWithIV).IsInstanceOfType(parameters)) { ParametersWithIV ivParam = (ParametersWithIV)parameters; byte[] iv = ivParam.getIV(); if (iv.Length != blockSize) { throw new ArgumentException("initialisation vector must be the same length as block size"); } Array.Copy(iv, 0, IV, 0, iv.Length); reset(); cipher.init(encrypting, ivParam.getParameters()); } else { reset(); cipher.init(encrypting, parameters); } }
/** * Initialise the cipher and, possibly, the initialisation vector (IV). * If an IV isn't passed as part of the parameter, the IV will be all zeros. * An IV which is too short is handled in FIPS compliant fashion. * * @param param the key and other data required by the cipher. * @exception ArgumentException if the params argument is * inappropriate. */ public void init( CipherParameters parameters) //throws ArgumentException { //this.encrypting = true; if (typeof(ParametersWithIV).IsInstanceOfType(parameters)) { ParametersWithIV ivParam = (ParametersWithIV)parameters; byte[] iv = ivParam.getIV(); if (iv.Length < IV.Length) { Array.Copy(iv, 0, IV, IV.Length - iv.Length, iv.Length); } else { Array.Copy(iv, 0, IV, 0, IV.Length); } reset(); cipher.init(true, ivParam.getParameters()); } else { reset(); cipher.init(true, parameters); } }
public byte[] wrap( byte[] inBytes, int inOff, int inLen) { if (!forWrapping) { throw new Exception("not set for wrapping"); } int n = inLen / 8; if ((n * 8) != inLen) { throw new DataLengthException("wrap data must be a multiple of 8 bytes"); } byte[] block = new byte[inLen + iv.Length]; byte[] buf = new byte[8 + iv.Length]; Array.Copy(iv, 0, block, 0, iv.Length); Array.Copy(inBytes, 0, block, iv.Length, inLen); engine.init(true, param); for (int j = 0; j != 6; j++) { for (int i = 1; i <= n; i++) { Array.Copy(block, 0, buf, 0, iv.Length); Array.Copy(block, 8 * i, buf, iv.Length, 8); engine.processBlock(buf, 0, buf, 0); int t = n * j + i; for (int k = 1; t != 0; k++) { byte v = (byte)t; buf[iv.Length - k] ^= v; t = (int)((uint)t >> 8); } Array.Copy(buf, 0, block, 0, 8); Array.Copy(buf, 8, block, 8 * i, 8); } } return(block); }
public void init( CipherParameters parameters) { reset(); cipher.init(true, parameters); }
/** * initialise the cipher. * * @param forEncryption if true the cipher is initialised for * encryption, if false for decryption. * @param param the key and other data required by the cipher. * @exception IllegalArgumentException if the params argument is * inappropriate. */ public virtual void init( bool forEncryption, CipherParameters parameters) //throws IllegalArgumentException { this.forEncryption = forEncryption; reset(); cipher.init(forEncryption, parameters); }
/** * Initialise the cipher and, possibly, the initialisation vector (IV). * If an IV isn't passed as part of the parameter, the IV will be all zeros. * An IV which is too short is handled in FIPS compliant fashion. * * @param forEncryption if true the cipher is initialised for * encryption, if false for decryption. * @param param the key and other data required by the cipher. * @exception IllegalArgumentException if the params argument is * inappropriate. */ public void init( bool encrypting, CipherParameters parameters) //throws ArgumentException { this.encrypting = encrypting; if (typeof(ParametersWithIV).IsInstanceOfType(parameters)) { ParametersWithIV ivParam = (ParametersWithIV)parameters; byte[] iv = ivParam.getIV(); if (iv.Length < IV.Length) { // prepend the supplied IV with zeros (per FIPS PUB 81) Array.Copy(iv, 0, IV, IV.Length - iv.Length, iv.Length); for (int i = 0; i < IV.Length - iv.Length; i++) { IV[i] = 0; } } else { Array.Copy(iv, 0, IV, 0, IV.Length); } reset(); cipher.init(true, ivParam.getParameters()); } else { reset(); cipher.init(true, parameters); } }
public void init(bool forEncryption, CipherParameters parameters) //throws IllegalArgumentException { this.encrypting = forEncryption; if (typeof(ParametersWithIV).IsInstanceOfType(parameters)) { ParametersWithIV ivParam = (ParametersWithIV)parameters; byte[] iv = ivParam.getIV(); Array.Copy(iv, 0, IV, 0, IV.Length); reset(); cipher.init(true, ivParam.getParameters()); } }
/** * initialise the underlying cipher. * * @param forEncryption true if we are setting up for encryption, false otherwise. * @param param the necessary parameters for the underlying cipher to be initialised. */ public void init( bool forEncryption, CipherParameters parameters) { cipher.init(forEncryption, parameters); }