/// <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; }
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); }
/// <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; }
/// <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; }
/// <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; }
/// <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; }
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"); }
/// <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; }
/// <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); } }
/// <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; }
/// <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; }