Guest User

Untitled

a guest
Feb 20th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.01 KB | None | 0 0
  1. //.h file code:
  2.  
  3. using namespace System;
  4.  
  5. public:
  6. static Object ^Rijndaelcrypt(String ^File, String ^Key);
  7.  
  8. static Object ^RijndaelDecrypt(String ^UDecryptU, String ^UKeyU);
  9.  
  10. //.cpp file code:
  11.  
  12. using namespace System;
  13.  
  14. Object ^<missing_class_definition>::Rijndaelcrypt(String ^File, String ^Key)
  15. {
  16.   RijndaelManaged ^oAesProvider = gcnew RijndaelManaged();
  17.   array<Byte> ^btClear = nullptr;
  18.   array<Byte> ^btSalt = gcnew array<Byte> {1, 2, 3, 4, 5, 6, 7, 8};
  19.   Rfc2898DeriveBytes ^oKeyGenerator = gcnew Rfc2898DeriveBytes(Key, btSalt);
  20.   oAesProvider->Key = oKeyGenerator->GetBytes(oAesProvider->Key->Length);
  21.   oAesProvider->IV = oKeyGenerator->GetBytes(oAesProvider->IV->Length);
  22.   IO::MemoryStream ^ms = gcnew IO::MemoryStream();
  23.   CryptoStream ^cs = gcnew CryptoStream(ms, oAesProvider->CreateEncryptor(), CryptoStreamMode::Write);
  24.   btClear = System::Text::Encoding::UTF8->GetBytes(File);
  25.   cs->Write(btClear, 0, btClear->Length);
  26.   cs->Close();
  27.   File = Convert::ToBase64String(ms->ToArray());
  28.   return File;
  29.     }
  30.  
  31. Object ^<missing_class_definition>::RijndaelDecrypt(String ^UDecryptU, String ^UKeyU)
  32. {
  33.   RijndaelManaged ^XoAesProviderX = gcnew RijndaelManaged();
  34.   array<Byte> ^XbtCipherX = nullptr;
  35.   array<Byte> ^XbtSaltX = gcnew array<Byte> {1, 2, 3, 4, 5, 6, 7, 8};
  36.   Rfc2898DeriveBytes ^XoKeyGeneratorX = gcnew Rfc2898DeriveBytes(UKeyU, XbtSaltX);
  37.   XoAesProviderX->Key = XoKeyGeneratorX->GetBytes(XoAesProviderX->Key->Length);
  38.   XoAesProviderX->IV = XoKeyGeneratorX->GetBytes(XoAesProviderX->IV->Length);
  39.   IO::MemoryStream ^XmsX = gcnew IO::MemoryStream();
  40.   CryptoStream ^XcsX = gcnew CryptoStream(XmsX, XoAesProviderX->CreateDecryptor(), CryptoStreamMode::Write);
  41.   try
  42.   {
  43.     XbtCipherX = Convert::FromBase64String(UDecryptU);
  44.     XcsX->Write(XbtCipherX, 0, XbtCipherX->Length);
  45.     XcsX->Close();
  46.     UDecryptU = System::Text::Encoding::UTF8->GetString(XmsX->ToArray());
  47.   }
  48.   catch(...)
  49.   {
  50.   }
  51.   return UDecryptU;
  52.     }[/CODE]
  53.  
  54. XOR:
  55. [CODE]//.h file code:
  56.  
  57. using namespace System;
  58.  
  59. public:
  60. String ^Encrypt(String ^CodeKey, String ^DataIn);
  61.  
  62.     String ^Decrypt(String ^CodeKey, String ^DataIn);
  63. ustub;
  64. /u;
  65.  
  66. Public Function ^(ByVal CodeKey As String, ByVal DataIn As String) As String;
  67.   Int64 lonDataPtr = 0;
  68.   String ^strDataOut = nullptr;
  69.   int intXOrValue1 = 0;
  70.   int intXOrValue2 = 0;
  71.  
  72.   for (lonDataPtr = 1; lonDataPtr <= (DataIn->Length / 2.0); lonDataPtr++)
  73.   {
  74.     intXOrValue1 = Microsoft::VisualBasic::Conversion::Val("&H" + (DataIn->Substring((2 * lonDataPtr) - 2, 2)));
  75.     intXOrValue2 = Convert::ToInt32(CodeKey[((lonDataPtr % CodeKey->Length) + 1) - 1]);
  76.  
  77.     strDataOut = strDataOut + (safe_cast<Char>(intXOrValue1 ^ intXOrValue2))->ToString();
  78.   }
  79.   xEncryption = strDataOut;
  80.     }
  81.  
  82. //.cpp file code:
  83.  
  84. using namespace System;
  85.  
  86. String ^<missing_class_definition>::Encrypt(String ^CodeKey, String ^DataIn)
  87. {
  88.   Int64 lonDataPtr = 0;
  89.   String ^strDataOut = nullptr;
  90.   int temp = 0;
  91.   String ^tempstring = nullptr;
  92.   int intXOrValue1 = 0;
  93.   int intXOrValue2 = 0;
  94.   for (lonDataPtr = 1; lonDataPtr <= DataIn->Length; lonDataPtr++)
  95.   {
  96.     intXOrValue1 = Convert::ToInt32(DataIn[lonDataPtr - 1]);
  97.     intXOrValue2 = Convert::ToInt32(CodeKey[((lonDataPtr % CodeKey->Length) + 1) - 1]);
  98.  
  99.     temp = (intXOrValue1 ^ intXOrValue2);
  100.     tempstring = Convert::ToString(temp, 16)->ToUpper();
  101.     if (tempstring->Length == 1)
  102.     {
  103.         tempstring = "0" + tempstring;
  104.     }
  105.     strDataOut = strDataOut + tempstring;
  106.   }
  107.   return strDataOut;
  108.     }
  109.  
  110. String ^<missing_class_definition>::Decrypt(String ^CodeKey, String ^DataIn)
  111. {
  112.   Int64 lonDataPtr = 0;
  113.   String ^strDataOut = nullptr;
  114.   int intXOrValue1 = 0;
  115.   int intXOrValue2 = 0;
  116.  
  117.   for (lonDataPtr = 1; lonDataPtr <= (DataIn->Length / 2.0); lonDataPtr++)
  118.   {
  119. intXOrValue1 = Microsoft::VisualBasic::Conversion::Val("&H" + (DataIn->Substring((2 * lonDataPtr) - 2, 2)));
  120. intXOrValue2 = Convert::ToInt32(CodeKey[((lonDataPtr % CodeKey->Length) + 1) - 1]);
  121.  
  122. strDataOut = strDataOut + (safe_cast<Char>(intXOrValue1 ^ intXOrValue2))->ToString();
  123.   }
  124.   return strDataOut;
  125. }
Add Comment
Please, Sign In to add comment