ToBase64String()的问题 引用自http://www.cnblogs.com/afxucamd/archive/2004/02/10/1128.html

About Convert.ToBase64String()

在使用Convert.ToBase64String()对字符串进行Base64编码时,注意的几点:
     例:string s = "Hello";
         byte[] bytes = Convert.FromBase64String(s);
  以上代码在运行时会抛出FormatException异常.提示为:Base-64字符数组的无效长度

原因:当Convert.FromBase64String方法的参数s的长度小于 4 或不是 4 的偶数倍时,将会抛出FormatException。
  
     例:
         Convert.FromBase64String("Hell");      // Normal.
         Convert.FromBase64String("Hell ");     // Normal.(忽略空格)
         Convert.FromBase64String("Hello!");    // throw FormatException.
         Convert.FromBase64String("Hello Net"); // Normal.(忽略空格)

原文地址:https://www.cnblogs.com/si812cn/p/1072279.html