Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #3 from dtaflin/master

Added Rijndael encryption
  • Loading branch information...
commit b3d9c0dc297316788bb9b328916b35229664c9f6 2 parents b07a572 + be5785f
@robertmircea authored
View
39 Nagios.NSCA.Client/AESEncryption.cs
@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.Cryptography;
+using System.Text;
+
+namespace Nagios.NSCA.Client
+{
+ public class AESEncryption : NSCAEncryptionBase
+ {
+ private int keyByteLength;
+
+ public AESEncryption(int keyByteLength)
+ {
+ this.keyByteLength = keyByteLength;
+ }
+
+ public override byte[] Encrypt(byte[] s, byte[] initVector, string password)
+ {
+ byte[] keyBytes = new byte[keyByteLength];
+ byte[] passwordBytes = Encoding.ASCII.GetBytes(password);
+ Buffer.BlockCopy(passwordBytes, 0, keyBytes, 0, Math.Min(keyByteLength, passwordBytes.Length));
+
+ byte[] iv = new byte[keyByteLength];
+ Buffer.BlockCopy(initVector, 0, iv, 0, Math.Min(keyByteLength, iv.Length));
+
+ using (RijndaelManaged crypto = new RijndaelManaged())
+ {
+ crypto.BlockSize = keyByteLength * 8;
+ crypto.Mode = CipherMode.CFB;
+ crypto.FeedbackSize = 8;
+ crypto.Padding = PaddingMode.Zeros;
+
+ var cryptoBytes = crypto.CreateEncryptor(keyBytes, iv).TransformFinalBlock(s, 0, s.Length);
+ return cryptoBytes;
+ }
+ }
+ }
+}
View
6 Nagios.NSCA.Client/EncryptorFactory.cs
@@ -14,6 +14,12 @@ public static NSCAEncryptionBase CreateEncryptor(NSCAEncryptionType encryptionTy
return new TripleDESEncryption();
case NSCAEncryptionType.None:
return new NoEncryption();
+ case NSCAEncryptionType.Rijndael128:
+ return new AESEncryption(16);
+ case NSCAEncryptionType.Rijndael192:
+ return new AESEncryption(24);
+ case NSCAEncryptionType.Rijndael256:
+ return new AESEncryption(32);
default:
throw new ArgumentOutOfRangeException("encryptionType");
}
View
5 Nagios.NSCA.Client/NSCAEncryptionType.cs
@@ -4,6 +4,9 @@ public enum NSCAEncryptionType
{
None,
Xor,
- TripleDES
+ TripleDES,
+ Rijndael128,
+ Rijndael192,
+ Rijndael256
}
}
View
1  Nagios.NSCA.Client/Nagios.NSCA.Client.csproj
@@ -42,6 +42,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="CRC32.cs" />
+ <Compile Include="AESEncryption.cs" />
<Compile Include="EncryptorFactory.cs" />
<Compile Include="INSCAClientSender.cs" />
<Compile Include="Level.cs" />
Please sign in to comment.
Something went wrong with that request. Please try again.