2015-02-26 2 views
1

У меня есть код, который отлично работает в Windows 7, но теперь я не могу использовать окно с Windows 8.1 (см. Ниже приведенный ниже код).CryptographicException (параметр неверен) в Windows 8.1, но не Windows 7

Является ли RSA отличным в Windows 8.1 и Windows 7?

using System.Security.Cryptography; 
using System.Text; 


namespace RsaBug 
{ 
    class Program 
    { 
     static void Main() 
     { 
      var modulus = Encoding.UTF8.GetBytes("rvco6d27bsw2fw5qx7okdcu5jahd1ifh22is76k5xyau3wjv7plo0rom66h2434tvm29cmq2ov6mbjo30bymb14j2dst5fzy7pd"); 
      var exponent = Encoding.UTF8.GetBytes("1ekh"); 

      using (var rsa = new RSACryptoServiceProvider()) 
      { 
       //Get an instance of RSAParameters from ExportParameters function. 
       var rsaKeyInfo = rsa.ExportParameters(false); 

       //Set RSAKeyInfo to the public key values. 
       rsaKeyInfo.Modulus = modulus; 
       rsaKeyInfo.Exponent = exponent; 

       //Import key parameters into RSA. 
       rsa.ImportParameters(rsaKeyInfo); // on Windows 8.1, this throws 
      } 
     } 
    } 
} 

Вот исключение я получаю:

System.Security.Cryptography.CryptographicException was unhandled 
    _HResult=-2147024809 
    _message=The parameter is incorrect. 

    HResult=-2147024809 
    IsTransient=false 
    Message=The parameter is incorrect. 

    Source=mscorlib 
    StackTrace: 
     at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr) 
     at System.Security.Cryptography.Utils._ImportKey(SafeProvHandle hCSP, Int32 keyNumber, CspProviderFlags flags, Object cspObject, SafeKeyHandle& hKey) 
     at System.Security.Cryptography.RSACryptoServiceProvider.ImportParameters(RSAParameters parameters) 
     at RsaBug.Program.Main() in d:\sandbox\2015\RsaBug\RsaBug\Program.cs:line 24 
     at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
     at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) 
     at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 
     at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
     at System.Threading.ThreadHelper.ThreadStart() 
    InnerException: 
+1

@GregS: ваше предложение основания-36 было на месте. Чтобы добавить к сложности, выясняется, что результирующий массив нужно поменять, прежде чем он будет использоваться для параметров RSA. Вы хотите предложить ответ, чтобы я мог его принять? – Hugh

ответ

2

на основе алфавита представить это, вероятно, что модуль и показатель низкопробны-36 кодированный.

Смежные вопросы