static void Main(string[] args)
{
// THIS IS JUST A SAMPLE 16 BYTE KEY!!! //
String secretKey = "password";
// For this demo, we are using a local file //
//String inputFile = "BatchSerialTransImport_20141106_0002_Sample.xlsx.encrypted";
String inputFile = "test.xlsx.encrypted";
// ...and saving to a local file too! //
String outputFile = "test.xlsx";
try
{
// We are using an AES Crypto with ECB and PKCS7 Padding
using (RijndaelManaged aes = new RijndaelManaged())
{
byte[] key = ASCIIEncoding.UTF8.GetBytes(secretKey);
byte[] IV = ASCIIEncoding.UTF8.GetBytes(secretKey);
aes.Mode = CipherMode.ECB;
aes.Padding = PaddingMode.PKCS7;
using (FileStream fsCrypt = new FileStream(inputFile, FileMode.Open))
{
using (FileStream fsOut = new FileStream(outputFile, FileMode.Create))
{
using (ICryptoTransform decryptor = aes.CreateDecryptor(key, IV))
{
using (CryptoStream cs = new CryptoStream(fsCrypt, decryptor, CryptoStreamMode.Read))
{
int data;
while ((data = cs.ReadByte()) != -1)
{
fsOut.WriteByte((byte)data);
}
cs.Flush();
cs.Close();
fsOut.Flush();
fsOut.Close();
fsCrypt.Close();
}
}
}
}
}
}
catch (Exception ex)
{
// failed to decrypt file
Console.WriteLine("Errors : "+ex.Message);
}
Console.ReadLine();
}
I am using the code above, it works when I decrypt anything from C#. problem is - I want to add UI and change to laravel.
This code works - write encrypted file name in inputFile field and password in secretKey field - run - generate decrypt file
How can I get this type of decryption in laravel/php ?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire