c# rsa加密需要xml公钥 如何将pem格式转换成xml
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQD5MIb5ZQhNGhsUjfFbn7y6nY6tsqV9LcC2s/rLpu9sz8CplsTy2SuTG0o7y9ICXW6oRUC9bVxI8TfTK4bbSrNQ6UoExzQFdbc3pEGun3iCy+inBhIC6xf5Z7lN+WqTKCZ607iLwKh+wDdZc6U4x1rxF4vngk1sXIdnYEoGjpRNLQIDAQAB
-----END PUBLIC KEY-----
使用BouncyCastle组件
1 /// <summary> 2 /// RSA公钥格式转换, 3 /// </summary> 4 /// <param name="publicKey">pem公钥</param> 5 /// <returns></returns> 6 public static string RSAPublicKeyJava2DotNet(string publicKey) 7 { 8 RsaKeyParameters publicKeyParam = (RsaKeyParameters)PublicKeyFactory.CreateKey(Convert.FromBase64String(publicKey)); 9 return string.Format("<RSAKeyValue><Modulus>{0}</Modulus><Exponent>{1}</Exponent></RSAKeyValue>", 10 Convert.ToBase64String(publicKeyParam.Modulus.ToByteArrayUnsigned()), 11 Convert.ToBase64String(publicKeyParam.Exponent.ToByteArrayUnsigned())); 12 }