コード例 #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);
			}
		}
コード例 #4
0
		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
ファイル: Key.cs プロジェクト: sharedsafe/SharedSafe.Encoding
		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);
		}
コード例 #13
0
		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));
		}