0

Here I am trying to decrpyt a string using private key and getting an error like:

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.

The string(i.e string authenticationString) which i am trying to decrpyt is:

Z7W7ja7G+NB3+QsbNnsz7zCkt1xeZ1PQC606wZzQG2McjExT6WjFPDWNpVSqcw1X+K6TERZUK4677m5Z6x9TuxLxyA8h8LmB4dwcJsQZGoVg0mOLsxO6GZmdThLyQOxQgnA7sk4KHLv6DrVswtVzjM/gJouvDKHTC7+NZmjhWwA=

and my code is:

 internal virtual Credentials Extract(string basicAuthenticationCredentials)
      {
         string authenticationString = RemoveBasicFromAuthenticationString(basicAuthenticationCredentials);
         string privateKeyPath = @"D:\Bala\MVC\RestService\RestClient\Scripts\PrivateKey.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));
      }

and in string au I am geting a value like:

d��!���u�I|�3��iaȴ{ȱ��q��A��z��ta �i8?�-�[�#�*&��Y^l,�v������ā�\�f�$R�V����&g;�</p>

and am getting this error for a particular username password only. Others are working fine. Any suggestion?

EDIT: The error is throwing in this line byte[] decodedStringInBytes = Convert.FromBase64String(encodedValue);

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

EDIT 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");
      }
   }
4

2 回答 2

2

您获得值的事实au表明,错误不是问题中的 base-64 解码。我将假设实际上是最后一行失败,并且期望 base-64 - 而您使用的是 UTF-8(我怀疑是向后,这是无效的)。尝试:

     message = myRsa.PrivateDecryption(decMessage);
     string au = Convert.ToBase64String(message);
     return extractor.Extract(decoder.Decode(au));
于 2012-12-12T08:04:31.090 回答
-4

卸载 64 位 c++ 重新分发并安装 x84,你应该没有问题。祝你好运!

于 2013-07-23T14:17:51.043 回答