6

Tôi cần làm cho mã sau hoạt động trên WP8, vấn đề là không có lớp X509Certificate2 trên WP8, tôi đã thử dùng apis bouncy castle nhưng tôi chưa thực sự quản lý nó ngoài.X509Certificate2 to X509Certificate trên Windows Phone 8

Có cách nào để làm cho mã này hoạt động trên WP8 không?

private string InitAuth(X509Certificate2 certificate, string systemId, string username, string password) 
    { 
     byte[] plainBytes = Encoding.UTF8.GetBytes(password); 
     var cipherB64 = string.Empty; 
     using (var rsa = (RSACryptoServiceProvider)certificate.PublicKey.Key) 
      cipherB64 = systemId + "^" + username + "^" + Convert.ToBase64String(rsa.Encrypt(plainBytes, true)); 

     return cipherB64; 
    } 

Trả lời

1

Bạn không thể làm việc xung quanh tính khả dụng của X509Certificate2?

private string InitAuth(X509Certificate certificate, string systemId, string username, string password) 
    { 
     byte[] plainBytes = Encoding.UTF8.GetBytes(password); 
     var cipherB64 = string.Empty; 

     //Create a new instance of RSACryptoServiceProvider. 
     RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(); 

     //Create a new instance of RSAParameters. 
     RSAParameters RSAKeyInfo = new RSAParameters(); 

     //Set RSAKeyInfo to the public key values. 
     RSAKeyInfo.Modulus = certificate.getPublicKey(); 
     RSAKeyInfo.Exponent = new byte[3] {1,0,1};; 

     //Import key parameters into RSA. 
     RSA.ImportParameters(RSAKeyInfo); 

     using (RSA) 
      cipherB64 = systemId + "^" + username + "^" + Convert.ToBase64String(RSA.Encrypt(plainBytes, true)); 

     return cipherB64; 
    } 

TUYÊN BỐ: Tôi không thử mã ở trên vì hiện tại tôi không có môi trường chạy thử C#.

+0

Tôi sẽ thử điều đó, cảm ơn – jjdev80

+0

@MaryJ. bạn đã xem nó chưa? – likeitlikeit

+0

Không, xin lỗi, tôi chưa có thời gian để làm điều đó chưa – jjdev80

Các vấn đề liên quan