コード例 #1
0
ファイル: AES192CBC.cs プロジェクト: LunarLanding/ngit
		/// <exception cref="System.Exception"></exception>
		public override void Init(int mode, byte[] key, byte[] iv)
		{
			string pad = "NoPadding";
			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
			{
				SecretKeySpec keyspec = new SecretKeySpec(key, "AES");
				cipher = Sharpen.Cipher.GetInstance("AES/CBC/" + pad);
				cipher.Init((mode == ENCRYPT_MODE ? Sharpen.Cipher.ENCRYPT_MODE : Sharpen.Cipher.
					DECRYPT_MODE), keyspec, new IvParameterSpec(iv));
			}
			catch (Exception e)
			{
				cipher = null;
				throw;
			}
		}
コード例 #2
0
 /// <exception cref="System.Exception"></exception>
 public override void Init(int mode, byte[] key, byte[] iv)
 {
     byte[] 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("RC4");
         SecretKeySpec _key = new SecretKeySpec(key, "RC4");
         cipher.Init((mode == ENCRYPT_MODE ? Sharpen.Cipher.ENCRYPT_MODE : Sharpen.Cipher.
                      DECRYPT_MODE), _key);
         byte[] foo = new byte[1];
         for (int i = 0; i < skip; i++)
         {
             cipher.Update(foo, 0, 1, foo, 0);
         }
     }
     catch (Exception e)
     {
         cipher = null;
         throw;
     }
 }
コード例 #3
0
ファイル: ARCFOUR256.cs プロジェクト: LunarLanding/ngit
		/// <exception cref="System.Exception"></exception>
		public override void Init(int mode, byte[] key, byte[] iv)
		{
			byte[] 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("RC4");
				SecretKeySpec _key = new SecretKeySpec(key, "RC4");
				cipher.Init((mode == ENCRYPT_MODE ? Sharpen.Cipher.ENCRYPT_MODE : Sharpen.Cipher.
					DECRYPT_MODE), _key);
				byte[] foo = new byte[1];
				for (int i = 0; i < skip; i++)
				{
					cipher.Update(foo, 0, 1, foo, 0);
				}
			}
			catch (Exception e)
			{
				cipher = null;
				throw;
			}
		}
コード例 #4
0
ファイル: TripleDESCTR.cs プロジェクト: LunarLanding/ngit
		/// <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;
			}
		}
コード例 #5
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
            {
                SecretKeySpec skeySpec = new SecretKeySpec(key, "Blowfish");
                cipher = Sharpen.Cipher.GetInstance("Blowfish/CBC/" + pad);
                cipher.Init((mode == ENCRYPT_MODE ? Sharpen.Cipher.ENCRYPT_MODE : Sharpen.Cipher.
                             DECRYPT_MODE), skeySpec, new IvParameterSpec(iv));
            }
            catch (Exception e)
            {
                throw;
            }
        }
コード例 #6
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;
            }
        }
コード例 #7
0
ファイル: WalkEncryption.cs プロジェクト: shoff/ngit
 /// <exception cref="System.IO.IOException"></exception>
 internal override InputStream Decrypt(InputStream @in)
 {
     try
     {
         Sharpen.Cipher c = Sharpen.Cipher.GetInstance(algorithmName);
         c.Init(Sharpen.Cipher.DECRYPT_MODE, skey, aspec);
         return(new CipherInputStream(@in, c));
     }
     catch (NoSuchAlgorithmException e)
     {
         throw Error(e);
     }
     catch (NoSuchPaddingException e)
     {
         throw Error(e);
     }
     catch (InvalidKeyException e)
     {
         throw Error(e);
     }
     catch (InvalidAlgorithmParameterException e)
     {
         throw Error(e);
     }
 }
コード例 #8
0
ファイル: WalkEncryption.cs プロジェクト: shoff/ngit
 /// <exception cref="System.IO.IOException"></exception>
 internal override OutputStream Encrypt(OutputStream os)
 {
     try
     {
         Sharpen.Cipher c = Sharpen.Cipher.GetInstance(algorithmName);
         c.Init(Sharpen.Cipher.ENCRYPT_MODE, skey, aspec);
         return(new CipherOutputStream(os, c));
     }
     catch (NoSuchAlgorithmException e)
     {
         throw Error(e);
     }
     catch (NoSuchPaddingException e)
     {
         throw Error(e);
     }
     catch (InvalidKeyException e)
     {
         throw Error(e);
     }
     catch (InvalidAlgorithmParameterException e)
     {
         throw Error(e);
     }
 }
コード例 #9
0
ファイル: ARCFOUR.cs プロジェクト: LunarLanding/ngit
		/// <exception cref="System.Exception"></exception>
		public override void Init(int mode, byte[] key, byte[] iv)
		{
			string pad = "NoPadding";
			byte[] 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("RC4");
				SecretKeySpec _key = new SecretKeySpec(key, "RC4");
				cipher.Init((mode == ENCRYPT_MODE ? Sharpen.Cipher.ENCRYPT_MODE : Sharpen.Cipher.
					DECRYPT_MODE), _key);
			}
			catch (Exception e)
			{
				cipher = null;
				throw;
			}
		}
コード例 #10
0
        /// <exception cref="System.Exception"></exception>
        public override void Init(int mode, byte[] key, byte[] iv)
        {
            string pad = "NoPadding";

            byte[] 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("RC4");
                SecretKeySpec _key = new SecretKeySpec(key, "RC4");
                cipher.Init((mode == ENCRYPT_MODE ? Sharpen.Cipher.ENCRYPT_MODE : Sharpen.Cipher.
                             DECRYPT_MODE), _key);
            }
            catch (Exception e)
            {
                cipher = null;
                throw;
            }
        }