summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.OAuth2/OAuth2/Crypto/JweRsaEncryptionAlgorithm.cs
blob: 0d2159d5dc42a5232f499d4e3d5cc556652b04f3 (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
namespace DotNetOpenAuth.OAuth2.Crypto {
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Security.Cryptography;
	using System.Text;

	internal class JweRsaEncryptionAlgorithm : JwtEncryptionAlgorithm {
		private readonly RSACryptoServiceProvider recipientPublicKey;

		private readonly bool useOaepPadding;

		internal JweRsaEncryptionAlgorithm(RSACryptoServiceProvider recipientPublicKey, bool useOaepPadding = true)
			: base(useOaepPadding ? JsonWebEncryptionAlgorithms.RSA_OAEP : JsonWebEncryptionAlgorithms.RSA1_5, JsonWebEncryptionMethods.A256CBC) {
			Requires.NotNull(recipientPublicKey, "recipientPublicKey");
			this.recipientPublicKey = recipientPublicKey;
			this.useOaepPadding = useOaepPadding;
		}

		internal override void Encrypt(byte[] plainText, out byte[] cipherText, out byte[] integrityValue) {
			cipherText = this.recipientPublicKey.Encrypt(plainText, this.useOaepPadding);
			integrityValue = null; // RSA is an AEAD algorithm, so it doesn't need a separate integrity check.
		}

		internal override byte[] Decrypt(byte[] cipherText, byte[] integrityValue) {
			throw new NotImplementedException();
		}
	}
}