Пример #1
0
		static bool verify(Key key, Signature signature, byte[] data)
		{
			using (var dsa = useSigningService(key))
			{
				return dsa.verify(data, signature);
			}
		}
Пример #2
0
		static Key removePrivateKey(Key key)
		{
			using (var dsa = useSigningService(key))
			{
				return dsa.exportKey(false);
			}
		}
Пример #3
0
		static Signature sign(Key key, byte[] data)
		{
			using (var dsa = useSigningService(key))
			{
				var signed = dsa.sign(data);
				return new Signature(new SignatureFormat(key.Format, DefaultHashAlgorithm), signed);
			}
		}
		public EncryptionService(Key key)
		{
			_provider = new AesCryptoServiceProvider
			{
				KeySize = key.Format.BitSize.signed(), 
				Key = key.Data
			};

			_outputStream = new ReusableMemoryStream();
		}
Пример #5
0
		// Create an object of type IV from a given object of type Key.
		// Usage of AesCryptoServiceProvider:
		// - create it 
		// - set its key size according the the size of the input Key
		// - use GenerateIV()
		public static IV createRandomIV(Key key)
		{
			using (var aes = new AesCryptoServiceProvider())
			{
				aes.KeySize = key.Format.BitSize.signed();
				// this should not be required?
				// aes.Key = key.Data;

				aes.GenerateIV();
				return new IV(aes.IV);
			}
		}
Пример #6
0
		public bool isSame(Key other)
		{
			return Format == other.Format && isSame(Data, other.Data);
		}
Пример #7
0
		static ISigningService useSigningService(Key key)
		{
			switch (key.Format.Algorithm)
			{
				case DSASigningService.AlgorithmName:
					return new DSASigningService(key);
			}

			throw new InternalError("Unsupported key algorithm {0}".format(key.Format.Algorithm));
		}
Пример #8
0
		static bool hasPrivateKey(Key key)
		{
			var without = removePrivateKey(key);
			return !without.isSame(key);
		}
Пример #9
0
		// Return decrypted data by using DecryptionService and the given Key
		public static BufferReference decrypt(Key key, BufferReference content)
		{
			using (var service = new DecryptionService(key))
			{
				return service.decrypt(content);
			}
		}
Пример #10
0
		// Return decrypted data by using DecryptionService and the given Key
		public static BufferReference decrypt(Key key, byte[] content)
		{
			return decrypt(key, content.asBufferReference());
		}
Пример #11
0
		public static BufferReference encrypt(Key key, IV? iv_, BufferReference content)
		{
			using (var service = new EncryptionService(key))
			{
				var iv = iv_ ?? service.createRandomIV();
				return service.encrypt(iv, content);
			}
		}
Пример #12
0
		public static BufferReference encrypt(Key key, BufferReference content)
		{
			return encrypt(key, null, content);
		}
		public DSASigningService(Key key)
		{
			Debug.Assert(key.Format.Algorithm == AlgorithmName);
			_provider = new DSACryptoServiceProvider(key.Format.BitSize.signed());
			_provider.FromXmlString(System.Text.Encoding.UTF8.GetString(key.Data));
		}