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

1234567891011121314151617181920212223242526272829303132333435363738
  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 = "426KOBTS66KYLFLQ";
  17. string key = "u1GIRvmnIFFHLov";
  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. // Decode it
  26. byte[] decodedSecret = Convert.FromBase64String(finalSecret);
  27. byte[] val = Aes128CFB.Decrypt(decodedSecret, keyBytes);
  28. string verify = Encoding.UTF8.GetString(val);
  29. Assert.Equal(secret, verify);
  30. }
  31. }
  32. }