Converting text using Base64 in Linux and Windows
开发者_高级运维I need to encrypt text/files in base 64 so I can send them in an email (I can't do attachments). I can use openSSL and GPG in Linux to encrypt and decrypt but don't know how to do the same in Windows XP. Does anyone know a program that can do this for me in windows?
EDITED AGAIN
In this link you can find how to encode/decode files.
I attach sample code:
private string FileToBase64(string srcFilename)
{
if (!string.IsNullOrEmpty(srcFilename))
{
FileStream fs = new FileStream(srcFilename,
FileMode.Open,
FileAccess.Read);
byte[] filebytes = new byte[fs.Length];
fs.Read(filebytes, 0, Convert.ToInt32(fs.Length));
string encodedData = Convert.ToBase64String(filebytes,
Base64FormattingOptions.InsertLineBreaks);
return encodedData;
}
}
private void Base64ToFile(string src, string dstFilename)
{
if (!string.IsNullOrEmpty(dstFilename))
{
byte[] filebytes = Convert.FromBase64String(src);
FileStream fs = new FileStream(dstFilename,
FileMode.CreateNew,
FileAccess.Write,
FileShare.None);
fs.Write(filebytes, 0, filebytes.Length);
fs.Close();
}
}
精彩评论