summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.OAuth2/OAuth2/Crypto/JwtEncryptionAlgorithm.cs
blob: b3ac78b9485feb09275d5c0be5320129ec83b4fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//-----------------------------------------------------------------------
// <copyright file="JwtEncryptionAlgorithm.cs" company="Andrew Arnott">
//     Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace DotNetOpenAuth.OAuth2.Crypto {
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Text;
	using DotNetOpenAuth.Messaging;

	internal abstract class JwtEncryptionAlgorithm : IDisposable {
		protected JwtEncryptionAlgorithm(string algorithmName, string encryptionMethod) {
			Requires.NotNullOrEmpty(algorithmName, "algorithmName");
			Requires.NotNullOrEmpty(encryptionMethod, "encryptionMethod");
			this.Header = new JweHeader(algorithmName, encryptionMethod);
		}

		internal JweHeader Header { get; private set; }

		internal abstract void Encrypt(byte[] plainText, out byte[] cipherText, out byte[] integrityValue);

		internal abstract byte[] Decrypt(byte[] cipherText, byte[] integrityValue);

		public void Dispose() {
			this.Dispose(true);
			GC.SuppressFinalize(this);
		}

		protected virtual void Dispose(bool disposing) {
		}

		protected void KeyDerivation(byte[] contentMasterKey, out byte[] contentEncryptionKey, out byte[] contentIntegrityKey) {
			// Implementing this would be manual, or involve P/Invoke I think.
			// http://msdn.microsoft.com/en-us/library/windows/desktop/aa375393(v=vs.85).aspx
			throw new NotImplementedException();
		}
	}
}