简体   繁体   English

在 Linux 和 Windows 中使用 Base64 转换文本

[英]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).我需要加密基于 64 位的文本/文件,以便我可以将它们发送到 email (我不能做附件)。 I can use openSSL and GPG in Linux to encrypt and decrypt but don't know how to do the same in Windows XP.我可以在 Linux 中使用 openSSL 和 GPG 进行加密和解密,但不知道如何在 Windows XP 中执行相同操作。 Does anyone know a program that can do this for me in windows?有谁知道可以在 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(); 
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM