Results 1 to 2 of 2

Thread: Rijndael Cryptography

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2011
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    1

    Default Rijndael Cryptography

    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 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Rijndael Cryptography

    Qt has no AES encryption or decryption capability. You can use any third-party library you like. One Qt-like wrapper is QCA, or you could use OpenSSL (libcrypto) directly.

Similar Threads

  1. Cryptography and export
    By DanH in forum Qt Programming
    Replies: 0
    Last Post: 13th April 2011, 15:42
  2. Cryptography classes: md5crypt and standard DES
    By bootsector in forum Qt Programming
    Replies: 3
    Last Post: 25th March 2009, 10:53
  3. Cryptography : is it me ???
    By fullmetalcoder in forum General Discussion
    Replies: 49
    Last Post: 2nd March 2007, 08:07

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.