Página 1 de 2

[DLL] RijndaelCrypt 1.0.0.0

Publicado: 22 Mar 2013 19:31
por Ceone
Información:

Buenas amigos de AMSSpecialist después de mucho mirar he encontrado una buena función para encriptar y desencriptar contenidos en Rijndael, esta DLL solo trae dos funciones pero cada función con 7 parámetros para llevar a otro nivel nuestros contenidos encriptados, espero que os guste y la disfrutéis.

Funciones:
  • RijndaelEncrypt
  • RijndaelDecrypt
Mas Información de las funciones:
Spoiler: Mostrar

Código: Seleccionar todo

    /// <summary>
    /// Encrypts specified plaintext using Rijndael symmetric key algorithm
    /// and returns a base64-encoded result.
    /// </summary>
    /// <param name="plainText">
    /// Plaintext value to be encrypted.
    /// </param>
    /// <param name="passPhrase">
    /// Passphrase from which a pseudo-random password will be derived. The
    /// derived password will be used to generate the encryption key.
    /// Passphrase can be any string. In this example we assume that this
    /// passphrase is an ASCII string.
    /// </param>
    /// <param name="saltValue">
    /// Salt value used along with passphrase to generate password. Salt can
    /// be any string. In this example we assume that salt is an ASCII string.
    /// </param>
    /// <param name="hashAlgorithm">
    /// Hash algorithm used to generate password. Allowed values are: "MD5" and
    /// "SHA1". SHA1 hashes are a bit slower, but more secure than MD5 hashes.
    /// </param>
    /// <param name="passwordIterations">
    /// Number of iterations used to generate password. One or two iterations
    /// should be enough.
    /// </param>
    /// <param name="initVector">
    /// Initialization vector (or IV). This value is required to encrypt the
    /// first block of plaintext data. For RijndaelManaged class IV must be 
    /// exactly 16 ASCII characters long.
    /// </param>
    /// <param name="keySize">
    /// Size of encryption key in bits. Allowed values are: 128, 192, and 256. 
    /// Longer keys are more secure than shorter keys.
    /// </param>
    /// <returns>
    /// Encrypted value formatted as a base64-encoded string.
    /// </returns>
    public static string RijndaelEncrypt(string   plainText,
                                 string   passPhrase,
                                 string   saltValue,
                                 string   hashAlgorithm,
                                 int      passwordIterations,
                                 string   initVector,
                                 int      keySize

Código: Seleccionar todo

    /// <summary>
    /// Decrypts specified ciphertext using Rijndael symmetric key algorithm.
    /// </summary>
    /// <param name="cipherText">
    /// Base64-formatted ciphertext value.
    /// </param>
    /// <param name="passPhrase">
    /// Passphrase from which a pseudo-random password will be derived. The
    /// derived password will be used to generate the encryption key.
    /// Passphrase can be any string. In this example we assume that this
    /// passphrase is an ASCII string.
    /// </param>
    /// <param name="saltValue">
    /// Salt value used along with passphrase to generate password. Salt can
    /// be any string. In this example we assume that salt is an ASCII string.
    /// </param>
    /// <param name="hashAlgorithm">
    /// Hash algorithm used to generate password. Allowed values are: "MD5" and
    /// "SHA1". SHA1 hashes are a bit slower, but more secure than MD5 hashes.
    /// </param>
    /// <param name="passwordIterations">
    /// Number of iterations used to generate password. One or two iterations
    /// should be enough.
    /// </param>
    /// <param name="initVector">
    /// Initialization vector (or IV). This value is required to encrypt the
    /// first block of plaintext data. For RijndaelManaged class IV must be
    /// exactly 16 ASCII characters long.
    /// </param>
    /// <param name="keySize">
    /// Size of encryption key in bits. Allowed values are: 128, 192, and 256.
    /// Longer keys are more secure than shorter keys.
    /// </param>
    /// <returns>
    /// Decrypted string value.
    /// </returns>
    /// <remarks>
    /// Most of the logic in this function is similar to the Encrypt
    /// logic. In order for decryption to work, all parameters of this function
    /// - except cipherText value - must match the corresponding parameters of
    /// the Encrypt function which was called to generate the
    /// ciphertext.
    /// </remarks>
    public static string RijndaelDecrypt(string   cipherText,
                                 string   passPhrase,
                                 string   saltValue,
                                 string   hashAlgorithm,
                                 int      passwordIterations,
                                 string   initVector,
                                 int      keySize)

Código::
using System;
using System.IO;
using System.Text;
using System.Security.Cryptography;
using RGiesecke.DllExport;
using System.Collections.Generic;

namespace RijndaelCrypt
{
internal static class RijndaelSimple
{
[DllExport("RijndaelEncrypt", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static string RijndaelEncrypt(string plainText, string passPhrase, string saltValue, string hashAlgorithm, int passwordIterations, string initVector, int keySize)
{
byte[] initVectorBytes = Encoding.ASCII.GetBytes(initVector);
byte[] saltValueBytes = Encoding.ASCII.GetBytes(saltValue);
byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, saltValueBytes, hashAlgorithm, passwordIterations);
byte[] keyBytes = password.GetBytes(keySize / 8);
RijndaelManaged symmetricKey = new RijndaelManaged();
symmetricKey.Mode = CipherMode.CBC;
ICryptoTransform encryptor = symmetricKey.CreateEncryptor(keyBytes, initVectorBytes);
MemoryStream memoryStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write);
cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
cryptoStream.FlushFinalBlock();
byte[] cipherTextBytes = memoryStream.ToArray();
memoryStream.Close();
cryptoStream.Close();
string cipherText = Convert.ToBase64String(cipherTextBytes);
return cipherText;
}

[DllExport("RijndaelDecrypt", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static string RijndaelDecrypt(string cipherText, string passPhrase, string saltValue, string hashAlgorithm, int passwordIterations, string initVector, int keySize)
{
byte[] initVectorBytes = Encoding.ASCII.GetBytes(initVector);
byte[] saltValueBytes = Encoding.ASCII.GetBytes(saltValue);
byte[] cipherTextBytes = Convert.FromBase64String(cipherText);
PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, saltValueBytes, hashAlgorithm, passwordIterations);
byte[] keyBytes = password.GetBytes(keySize / 8);
RijndaelManaged symmetricKey = new RijndaelManaged();
symmetricKey.Mode = CipherMode.CBC;
ICryptoTransform decryptor = symmetricKey.CreateDecryptor(keyBytes, initVectorBytes);
MemoryStream memoryStream = new MemoryStream(cipherTextBytes);
CryptoStream cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read);
byte[] plainTextBytes = new byte[cipherTextBytes.Length];
int decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length);
memoryStream.Close();
cryptoStream.Close();
string plainText = Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount);
return plainText;
}
}
}


Descarga:

HIDE: ON
Hidebb Message Hidden Description

Re: [DLL] RijndaelCrypt 1.0.0.0

Publicado: 29 Mar 2013 13:09
por Haitham.2012
gracias

Re: [DLL] RijndaelCrypt 1.0.0.0

Publicado: 29 Mar 2013 18:24
por sattel
Excelente

Re: [DLL] RijndaelCrypt 1.0.0.0

Publicado: 29 Mar 2013 19:08
por abood1987
thanks

Re: [DLL] RijndaelCrypt 1.0.0.0

Publicado: 29 Mar 2013 20:12
por mecivic
Thank you

Publicado: 05 Abr 2013 00:24
por Arseniy02
thanks

Publicado: 07 Ago 2013 01:40
por shane9082
thanks

Publicado: 30 Ago 2013 21:11
por chakal03
thanks

Publicado: 05 Ene 2014 18:08
por amsplug
ok :yeah: :yeah: :yeah: :yeah: :yeah:

Publicado: 09 Ene 2014 19:01
por mohsen
thanks

Publicado: 15 Ene 2014 18:48
por tairorojo
Gracias

Publicado: 15 Ene 2014 18:56
por tairorojo
Puedes subir la solucion c#, has dejado el codigo inivcial puedes subir el completo.

Gracias.

Publicado: 16 Ene 2014 04:27
por tam
gracias

Publicado: 23 Ene 2014 15:48
por patch
What makes this useful? I don't see point encrying and decrypitng in the same plugin as this means the project that might use this just to read the file would have the menas to do both so someone can hack it and have the means to in the same app.

Re: [DLL] RijndaelCrypt 1.0.0.0

Publicado: 13 Jul 2015 13:31
por (NA3R)
thank u for....

Re: [DLL] RijndaelCrypt 1.0.0.0

Publicado: 14 Jul 2015 06:49
por rhymelody
nice broo

Re: [DLL] RijndaelCrypt 1.0.0.0

Publicado: 12 Oct 2015 16:44
por holakase
servira para el chat que estoy aciendo

Re: [DLL] RijndaelCrypt 1.0.0.0

Publicado: 11 Nov 2015 02:06
por hddutilite
manda pra mim

Re: [DLL] RijndaelCrypt 1.0.0.0

Publicado: 03 Feb 2016 18:14
por Kindly
Muy bueno :)

Re: [DLL] RijndaelCrypt 1.0.0.0

Publicado: 05 Sep 2017 13:14
por usamakey
tnks my friend :lol: