hi everybody i have a friend that have a website with asp.net he encrypt data with Rijndael Cryptography and write to database i want in my qt application decrypt data and show the user how can i implement this algorithm in qt. this code is in asp.net that my friend use it to encrypt and decrypt data.
Qt Code:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Data.SqlClient;
  6.  
  7. namespace TSecurityWebApp.Classes
  8. {
  9. public class SecurityClass
  10. {
  11. public static readonly byte[] PKey = { 18, 45, 248, 40, 250, 160, 96, 102, 137, 39, 130, 244, 83, 242, 253, 221 };
  12. public static readonly byte[] PIV = { 200, 193, 57, 174, 121, 152, 246, 218, 171, 208, 106, 150, 93, 221, 160, 140 };
  13.  
  14. public static string DecodeData(string InputData, byte[] PKey, byte[] PIV)
  15. {
  16. string retStr = string.Empty;
  17. try
  18. {
  19. var r = System.Security.Cryptography.Rijndael.Create();
  20.  
  21. r.KeySize = 128;
  22. r.BlockSize = 128;
  23.  
  24. r.Key = PKey;
  25. r.IV = PIV;
  26.  
  27. byte[] inpBytes = new byte[InputData.Length / 2];
  28. for (int i = 0; i < InputData.Length / 2; i++)
  29. inpBytes[i] = byte.Parse((InputData[(i * 2)].ToString() + InputData[(i * 2 + 1)].ToString()), System.Globalization.NumberStyles.HexNumber);
  30. byte[] decBytes = r.CreateDecryptor().TransformFinalBlock(inpBytes, 0, inpBytes.Length);
  31.  
  32. r.Clear();
  33.  
  34. retStr = System.Text.UnicodeEncoding.Unicode.GetString(decBytes);
  35. }
  36. catch { retStr = string.Empty; }
  37. return retStr;
  38. }
  39.  
  40. public static string EncodeData(string InputData, byte[] PKey, byte[] PIV)
  41. {
  42. string retStr = string.Empty;
  43. try
  44. {
  45. var r = System.Security.Cryptography.Rijndael.Create();
  46.  
  47. r.KeySize = 128;
  48. r.BlockSize = 128;
  49.  
  50. r.Key = PKey;
  51. r.IV = PIV;
  52.  
  53. byte[] inpBytes = System.Text.UnicodeEncoding.Unicode.GetBytes(InputData);
  54. byte[] encBytes = r.CreateEncryptor().TransformFinalBlock(inpBytes, 0, inpBytes.Length);
  55.  
  56. r.Clear();
  57.  
  58. foreach (byte b in encBytes)
  59. retStr += b.ToString("X2");
  60. }
  61. catch { retStr = string.Empty; }
  62. return retStr;
  63. }
  64.  
  65. public static string EncriptConnStr(string ConnStr)
  66. {
  67. try
  68. {
  69. SqlConnectionStringBuilder connBuilder = new SqlConnectionStringBuilder(ConnStr);
  70. if (!string.IsNullOrEmpty(connBuilder.Password))
  71. connBuilder.Password = SecurityClass.EncodeData(connBuilder.Password, SecurityClass.PKey, SecurityClass.PIV);
  72. ConnStr = connBuilder.ConnectionString;
  73. }
  74. catch { ConnStr = string.Empty; }
  75. return ConnStr;
  76. }
  77.  
  78. public static string DecriptConnStr(string EncConnStr)
  79. {
  80. string decConnStr = EncConnStr;
  81. try
  82. {
  83. SqlConnectionStringBuilder connBuilder = new SqlConnectionStringBuilder(EncConnStr);
  84. if (!string.IsNullOrEmpty(connBuilder.Password))
  85. connBuilder.Password = SecurityClass.DecodeData(connBuilder.Password, SecurityClass.PKey, SecurityClass.PIV);
  86. decConnStr = connBuilder.ConnectionString;
  87. }
  88. catch { decConnStr = EncConnStr; }
  89. return decConnStr;
  90. }
  91. }
  92. }
To copy to clipboard, switch view to plain text mode