コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SymmetricCryptographicKey"/> class.
 /// </summary>
 /// <param name="algorithm">The algorithm, initialized with the key.</param>
 /// <param name="name">The name of the base algorithm to use.</param>
 /// <param name="mode">The algorithm's mode (i.e. streaming or some block mode).</param>
 /// <param name="padding">The padding to use.</param>
 internal SymmetricCryptographicKey(Platform.SymmetricAlgorithm algorithm, SymmetricAlgorithmName name, SymmetricAlgorithmMode mode, SymmetricAlgorithmPadding padding)
 {
     Requires.NotNull(algorithm, "algorithm");
     this.algorithm = algorithm;
     this.Name = name;
     this.Mode = mode;
     this.Padding = padding;
 }
コード例 #2
0
        public void PrepareRequest(IRestRequest request)
        {
            var signature = new ApiRequestSignature { AppId = _appId };

            var parameters = new[]
            {
                new NameValuePair(null, _appId),
                new NameValuePair(null, signature.TimestampString)
            };

            signature.Hash = HmacUtility.GetHashString(key => new HMACSHA256(key), _secretKey, parameters);
            request.AddHeader("Authorization", "HMACSHA256 " + signature);
        }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SymmetricCryptographicKey"/> class.
 /// </summary>
 /// <param name="algorithm">The algorithm, initialized with the key.</param>
 /// <param name="pclAlgorithm">The PCL enum of the algorithm in use.</param>
 internal SymmetricCryptographicKey(Platform.SymmetricAlgorithm algorithm, SymmetricAlgorithm pclAlgorithm)
 {
     Requires.NotNull(algorithm, "algorithm");
     this.algorithm = algorithm;
     this.pclAlgorithm = pclAlgorithm;
 }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CryptoTransformAdaptor"/> class.
 /// </summary>
 /// <param name="transform">The transform.</param>
 internal CryptoTransformAdaptor(Platform.ICryptoTransform transform)
 {
     Requires.NotNull(transform, "transform");
     this.transform = transform;
 }
コード例 #5
0
ファイル: JWK.cs プロジェクト: hallambaker/Mathematical-Mesh
 /// <summary>
 /// Construct from a .NET RSA Parameters structure.
 /// </summary>
 /// <param name="RSAParameters"></param>
 public PublicKeyRSA(NET.RSAParameters RSAParameters) {
     this.n = RSAParameters.Modulus;
     this.e = RSAParameters.Exponent;
     }
コード例 #6
0
ファイル: JWK.cs プロジェクト: hallambaker/Mathematical-Mesh
 /// <summary>
 /// Construct from a .NET RSA Parameters structure.
 /// </summary>
 /// <param name="RSAParameters"></param>
 public PrivateKeyRSA(NET.RSAParameters RSAParameters) : base (RSAParameters) {
     this.d = RSAParameters.D;
     this.p = RSAParameters.P;
     this.q = RSAParameters.Q;
     this.dp = RSAParameters.DP;
     this.dq = RSAParameters.DQ;
     this.qi = RSAParameters.InverseQ;
     }
コード例 #7
0
ファイル: MachineKeyTest.cs プロジェクト: Profit0004/mono
		public void Protect ()
		{
			AssertExtensions.Throws<ArgumentNullException> (() =>
				MachineKey.Protect (null, null), 
				"MachineKey.Protect not throwing an ArgumentNullException");

			AssertExtensions.Throws<ArgumentNullException> (() => 
				MachineKey.Protect (null, new [] { "test" }), 
				"MachineKey.Protect not throwing an ArgumentNullException");

			var testString = "asfgasd43tqrt4";
			var validUsages = new [] { "usage1", "usage2" };
			var oneUsage = new [] { "usage1" };
			var invalidUsages = new [] { "usage1", "invalidUsage" };

			var plainBytes = Encoding.ASCII.GetBytes (testString);
			var encryptedBytes = MachineKey.Protect (plainBytes, validUsages);
			var validDecryptedBytes = MachineKey.Unprotect (encryptedBytes, validUsages);

			Assert.AreEqual (plainBytes, validDecryptedBytes, "Decryption didn't work");

			AssertExtensions.Throws<CryptographicException> (() => 
				MachineKey.Unprotect (encryptedBytes, invalidUsages), 
				"Purposes not encrypting properly");

			AssertExtensions.Throws<CryptographicException> (() => 
				MachineKey.Unprotect (encryptedBytes, oneUsage), 
				"Single purpose working when multiple supplied");
		}
コード例 #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ECDiffieHellmanPublicKey"/> class.
        /// </summary>
        /// <param name="publicKey">The underlying platform public key.</param>
        internal ECDiffieHellmanPublicKey(Platform.ECDiffieHellmanPublicKey publicKey)
        {
            Requires.NotNull(publicKey, nameof(publicKey));

            this.publicKey = publicKey;
        }
コード例 #9
0
        /// <summary>
        /// Transforms an input block.
        /// </summary>
        /// <param name="transformField">Either the <see cref="encryptor"/> or <see cref="decryptor"/> field.</param>
        /// <param name="transformCreator">The function to create a new transformer.</param>
        /// <param name="data">The input data.</param>
        /// <param name="iv">The initialization vector.</param>
        /// <returns>The result of the transform.</returns>
        private byte[] CipherOperation(ref Platform.ICryptoTransform transformField, Func<SymmetricCryptographicKey, byte[], Platform.ICryptoTransform> transformCreator, byte[] data, byte[] iv)
        {
            Requires.NotNull(transformCreator, nameof(transformCreator));
            Requires.NotNull(data, nameof(data));

            if (this.Padding == SymmetricAlgorithmPadding.None && data.Length == 0)
            {
                return data;
            }

            if (iv != null || !this.CanStreamAcrossTopLevelCipherOperations || transformField == null)
            {
                transformField?.Dispose();
                transformField = transformCreator(this, iv);
            }

            if (this.CanStreamAcrossTopLevelCipherOperations)
            {
                byte[] outputBlock = new byte[data.Length];
                int bytesOutput = transformField.TransformBlock(data, 0, data.Length, outputBlock, 0);
                Array.Resize(ref outputBlock, bytesOutput);
                return outputBlock;
            }
            else
            {
                return transformField.TransformFinalBlock(data, 0, data.Length);
            }
        }
コード例 #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NetFxCryptographicHash"/> class.
        /// </summary>
        /// <param name="algorithm">The algorithm.</param>
        internal NetFxCryptographicHash(Platform.HashAlgorithm algorithm)
        {
            Requires.NotNull(algorithm, "algorithm");

            this.Algorithm = algorithm;
        }
コード例 #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ECDiffieHellman"/> class.
 /// </summary>
 /// <param name="platformAlgorithm">The .NET algorithm backing this instance.</param>
 internal ECDiffieHellman(Platform.ECDiffieHellman platformAlgorithm)
 {
     Requires.NotNull(platformAlgorithm, nameof(platformAlgorithm));
     this.platformAlgorithm = platformAlgorithm;
 }