CSharp - 输入不是有效的Base 64 字符串,因为它包含非 Base 64 字符?

在这里,我试图使用私钥解密字符串,并得到如下错误:

the input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters.

我正在尝试解密的字符串(i.n string authentication_String)是:

z7w7ja7g+nb3+qsbnnsz7zckt1xez1pqc606wzzqg2mcjext6wjfpdwnpvsqcw1x+k6terzuk4677m5z6x9tuxlxya8h8lmb4dwcjsqzgovg0molsxo6gzmdthlyqoxqgna7sk4khlv6drvswtvzjm/gjouvdkhtc7+nzmjhwwa =

代码是:


 internal virtual Credentials Extract(string basicAuthenticationCredentials)
 {
 string authenticationString = RemoveBasicFromAuthenticationString(basicAuthenticationCredentials);
 string privateKeyPath = @"D:BalaMVCRestServiceRestClientScriptsPrivateKey.xml";
 myRsa.LoadPrivateFromXml(privateKeyPath); // Loading the Private key
 RSACryptoServiceProvider localRsa = new RSACryptoServiceProvider();
 localRsa.FromXmlString(File.ReadAllText(privateKeyPath));
 byte[] decMessage = Convert.FromBase64String(authenticationString);
 byte[] message = null;
 // Calling the right decryption method according to the user selection
 message = myRsa.PrivateDecryption(decMessage);
 string au = Encoding.UTF8.GetString(message);
 return extractor.Extract(decoder.Decode(au));
 }

抛出此行错误: byte [] decodedStringInBytes = Convert.FromBase64String(encodedValue) ;


internal virtual string Decode(string encodedValue)
 {
 byte[] decodedStringInBytes = Convert.FromBase64String(encodedValue);
 return Encoding.ASCII.GetString(decodedStringInBytes);
 }

编辑2:


internal class DecodedCredentialsExtractor
 {
 internal virtual Credentials Extract(string credentials)
 {
 if (!string.IsNullOrEmpty(credentials))
 {
 string[] credentialTokens = credentials.Split(':');
 //string securityToken = string.Empty;
 if (credentialTokens.Length == 2)
 {
 return new Credentials(credentialTokens[0], credentialTokens[1]);
 }
 }

 throw new ArgumentException("The supplied credential string is invalid, it should comply to [username:password]","credentials");
 }
 }

时间:

尝试以下方法:


 message = myRsa.PrivateDecryption(decMessage);
 string au = Convert.ToBase64String(message);
 return extractor.Extract(decoder.Decode(au));

卸载64位c 重新发布,并安装x84,应该没有问题。

...