1
0
mirror of https://git.teknik.io/Teknikode/Teknik.git synced 2023-08-02 14:16:22 +02:00
Teknik/UtilitiesTests/Cryptography/Aes128Tests.cs
2017-06-11 00:06:00 -07:00

39 lines
1.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Teknik.Utilities;
using Teknik.Utilities.Cryptography;
using Xunit;
namespace Teknik.Tests.UtilitiesTests.Cryptography
{
public class Aes128Tests
{
[Fact]
public void Aes128DataTest()
{
string secret = "426KOBTS66KYLFLQ";
string key = "8fj3Ff83nfQoe01";
// Get the Encryption Key from the git secret key
byte[] keyBytes = MD5.Hash(Encoding.UTF8.GetBytes(key));
// Modify the input secret
byte[] secBytes = Encoding.UTF8.GetBytes(secret);
// Generate the encrypted secret using AES CGM
byte[] encValue = Aes128CFB.Encrypt(secBytes, keyBytes);
string finalSecret = Convert.ToBase64String(encValue);
// Decode it
byte[] decodedSecret = Convert.FromBase64String(finalSecret);
byte[] val = Aes128CFB.Decrypt(decodedSecret, keyBytes);
string verify = Encoding.UTF8.GetString(val);
Assert.Equal(secret, verify);
}
}
}