This repository has been archived by the owner on Nov 29, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Snippets.cs
52 lines (47 loc) · 1.4 KB
/
Snippets.cs
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
42
43
44
45
46
47
48
49
50
51
52
#pragma warning disable SYSLIB0022
using System.Security.Cryptography;
using Newtonsoft.Json;
using Newtonsoft.Json.Encryption;
using Rebus.Activation;
using Rebus.Config;
using Rebus.Handlers;
using Rebus.Newtonsoft.Encryption;
using Rebus.Serialization.Json;
// ReSharper disable UnusedParameter.Local
class Snippets
{
void Usage(byte[] key)
{
#region RebugsUsage
var activator = new BuiltinHandlerActivator();
activator.Register(() => new Handler());
var configurer = Configure.With(activator);
var encryptionFactory = new EncryptionFactory();
var settings = new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.All,
ContractResolver = encryptionFactory.GetContractResolver()
};
configurer.Serialization(s => { s.UseNewtonsoftJson(settings); });
configurer.EnableJsonEncryption(
encryptionFactory: encryptionFactory,
encryptStateBuilder: () =>
(
algorithm: new RijndaelManaged
{
Key = key
},
keyId: "1"
),
decryptStateBuilder: (keyId, initVector) =>
new RijndaelManaged
{
Key = key,
IV = initVector
});
#endregion
}
}
class Handler: IHandleMessages
{
}