我想解密excel文件并将数据存储到csv文件中。我可以在PHP中使用哪些方法?
我在C#中有解密文件的示例代码。
class Program
{
static void Main(string[] args)
{
// THIS IS JUST A SAMPLE 16 BYTE KEY!!! //
String secretKey = "050WC6tJuL@#*%^&";
// For this demo, we are using a local file //
String inputFile = "Sample.xlsx.encrypted";
// ...and saving to a local file too!
String outputFile = "Sample.csv";
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();
}
}