The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Aes128Tests.cs 1.1KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Teknik.Utilities;
  7. using Teknik.Utilities.Cryptography;
  8. using Xunit;
  9. namespace Teknik.Tests.UtilitiesTests.Cryptography
  10. {
  11. public class Aes128Tests
  12. {
  13. [Fact]
  14. public void Aes128DataTest()
  15. {
  16. string secret = "WXEYUXXH7X6OUVPK";
  17. string key = "df9Nfjhq89KAwvs";
  18. // Get the Encryption Key from the git secret key
  19. byte[] keyBytes = MD5.Hash(Encoding.UTF8.GetBytes(key));
  20. // Modify the input secret
  21. byte[] secBytes = Encoding.UTF8.GetBytes(secret);
  22. // Generate the encrypted secret using AES CGM
  23. byte[] encValue = Aes128CFB.Encrypt(secBytes, keyBytes);
  24. string finalSecret = Convert.ToBase64String(encValue);
  25. byte[] decodedSecret = Convert.FromBase64String(finalSecret);
  26. byte[] val = Aes128CFB.Decrypt(decodedSecret, keyBytes);
  27. string verify = Encoding.UTF8.GetString(val);
  28. Assert.Equal(secret, verify);
  29. }
  30. }
  31. }