Example #1
0
		/// <exception cref="System.Exception"></exception>
		public override void Init(int mode, byte[] key, byte[] iv)
		{
			string pad = "NoPadding";
			//if(padding) pad="PKCS5Padding";
			byte[] tmp;
			if (iv.Length > ivsize)
			{
				tmp = new byte[ivsize];
				System.Array.Copy(iv, 0, tmp, 0, tmp.Length);
				iv = tmp;
			}
			if (key.Length > bsize)
			{
				tmp = new byte[bsize];
				System.Array.Copy(key, 0, tmp, 0, tmp.Length);
				key = tmp;
			}
			try
			{
				cipher = Sharpen.Cipher.GetInstance("DESede/CTR/" + pad);
				DESedeKeySpec keyspec = new DESedeKeySpec(key);
				SecretKeyFactory keyfactory = SecretKeyFactory.GetInstance("DESede");
				SecretKey _key = keyfactory.GenerateSecret(keyspec);
				cipher.Init((mode == ENCRYPT_MODE ? Sharpen.Cipher.ENCRYPT_MODE : Sharpen.Cipher.
					DECRYPT_MODE), _key, new IvParameterSpec(iv));
			}
			catch (Exception e)
			{
				cipher = null;
				throw;
			}
		}
        public override SecretKey GenerateSecret(KeySpec key)
        {
            DESedeKeySpec ks = (DESedeKeySpec)key;

            return(new SecretKey(ks.Key));
        }