Example #1
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;
			}
		}
Example #2
0
		/// <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;
			}
		}
Example #3
0
		/// <exception cref="System.Exception"></exception>
		public virtual void Init(byte[] key)
		{
			if (key.Length > 20)
			{
				byte[] tmp = new byte[20];
				System.Array.Copy(key, 0, tmp, 0, 20);
				key = tmp;
			}
			SecretKeySpec skey = new SecretKeySpec(key, "HmacSHA1");
			mac = Mac.GetInstance("HmacSHA1");
			mac.Init(skey);
		}
Example #4
0
		/// <exception cref="System.Exception"></exception>
		public virtual void Init(byte[] key)
		{
			if (key.Length > BSIZE)
			{
				byte[] tmp = new byte[BSIZE];
				System.Array.Copy(key, 0, tmp, 0, BSIZE);
				key = tmp;
			}
			SecretKeySpec skey = new SecretKeySpec(key, "HmacMD5");
			mac = Mac.GetInstance("HmacMD5");
			mac.Init(skey);
		}
Example #5
0
        public override void Init(int mode, Key keyspec)
        {
            SecretKeySpec key = (SecretKeySpec)keyspec;

            if (mode == Cipher.ENCRYPT_MODE)
            {
                transformer = rc4.CreateEncryptor(key.Key, new byte[0]);
            }
            else
            {
                transformer = rc4.CreateDecryptor(key.Key, new byte[0]);
            }
        }
Example #6
0
        public override void Init(int mode, Key keyspec, IvParameterSpec spec)
        {
            SecretKeySpec key = (SecretKeySpec)keyspec;

            if (mode == Cipher.ENCRYPT_MODE)
            {
                transformer = encryptor.CreateEncryptor(key.Key, spec.Iv);
            }
            else
            {
                transformer = encryptor.CreateDecryptor(key.Key, spec.Iv);
            }
        }
Example #7
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;
			}
		}
Example #8
0
        public void Init(KeySpec key)
        {
            SecretKeySpec k = (SecretKeySpec)key;

            mac.Key = k.Key;
        }
Example #9
0
		/// <summary>Create a new S3 client for the supplied user information.</summary>
		/// <remarks>
		/// Create a new S3 client for the supplied user information.
		/// <p>
		/// The connection properties are a subset of those supported by the popular
		/// <a href="http://jets3t.s3.amazonaws.com/index.html">jets3t</a> library.
		/// For example:
		/// <pre>
		/// # AWS Access and Secret Keys (required)
		/// accesskey: &lt;YourAWSAccessKey&gt;
		/// secretkey: &lt;YourAWSSecretKey&gt;
		/// # Access Control List setting to apply to uploads, must be one of:
		/// # PRIVATE, PUBLIC_READ (defaults to PRIVATE).
		/// acl: PRIVATE
		/// # Number of times to retry after internal error from S3.
		/// httpclient.retry-max: 3
		/// # End-to-end encryption (hides content from S3 owners)
		/// password: &lt;encryption pass-phrase&gt;
		/// crypto.algorithm: PBEWithMD5AndDES
		/// </pre>
		/// </remarks>
		/// <param name="props">connection properties.</param>
		public AmazonS3(Sharpen.Properties props)
		{
			publicKey = props.GetProperty("accesskey");
			if (publicKey == null)
			{
				throw new ArgumentException(JGitText.Get().missingAccesskey);
			}
			string secret = props.GetProperty("secretkey");
			if (secret == null)
			{
				throw new ArgumentException(JGitText.Get().missingSecretkey);
			}
			privateKey = new SecretKeySpec(Constants.EncodeASCII(secret), HMAC);
			string pacl = props.GetProperty("acl", "PRIVATE");
			if (StringUtils.EqualsIgnoreCase("PRIVATE", pacl))
			{
				acl = "private";
			}
			else
			{
				if (StringUtils.EqualsIgnoreCase("PUBLIC", pacl))
				{
					acl = "public-read";
				}
				else
				{
					if (StringUtils.EqualsIgnoreCase("PUBLIC-READ", pacl))
					{
						acl = "public-read";
					}
					else
					{
						if (StringUtils.EqualsIgnoreCase("PUBLIC_READ", pacl))
						{
							acl = "public-read";
						}
						else
						{
							throw new ArgumentException("Invalid acl: " + pacl);
						}
					}
				}
			}
			try
			{
				string cPas = props.GetProperty("password");
				if (cPas != null)
				{
					string cAlg = props.GetProperty("crypto.algorithm");
					if (cAlg == null)
					{
						cAlg = "PBEWithMD5AndDES";
					}
					encryption = new WalkEncryption.ObjectEncryptionV2(cAlg, cPas);
				}
				else
				{
					encryption = WalkEncryption.NONE;
				}
			}
			catch (InvalidKeySpecException e)
			{
				throw new ArgumentException(JGitText.Get().invalidEncryption, e);
			}
			catch (NoSuchAlgorithmException e)
			{
				throw new ArgumentException(JGitText.Get().invalidEncryption, e);
			}
			maxAttempts = System.Convert.ToInt32(props.GetProperty("httpclient.retry-max", "3"
				));
			proxySelector = ProxySelector.GetDefault();
		}