我如何将 RsaKeyParameters 发送到服务器,反之亦然?
How can i send a RsaKeyParameters to a server or vice versa?
我在 Xamarin Forms 上使用 Bouncy Castle 进行非对称加密。但我正在研究客户端 <-> Web Api 结构。如何将 public 密钥发送到另一端?因为类型是 RsaKeyParameters .
RsaKeyPairGenerator rsaKeyPairGnr = new RsaKeyPairGenerator();
rsaKeyPairGnr.Init(new KeyGenerationParameters(new SecureRandom(), 512));
AsymmetricCipherKeyPair keyPair = rsaKeyPairGnr.GenerateKeyPair();
RsaKeyParameters publicKey = (RsaKeyParameters)keyPair.Public;
如果我有 RsaKeyParameters publicKey
并且需要将其发送到服务器,我可以使用以下方式进行转换:
//convert from key to string
SubjectPublicKeyInfo publicKeyInfo = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(publicKey);
byte[] serializedPublicBytes = publicKeyInfo.ToAsn1Object().GetDerEncoded();
string serializedPublic = Convert.ToBase64String(serializedPublicBytes);
And then, i can convert the serializedPublic to RsaKeyParameters publicKey
//convert from string to key
RsaKeyParameters publicKey2 = (RsaKeyParameters)PublicKeyFactory.CreateKey(Convert.FromBase64String(serializedPublic));
但是有人可以告诉我通过 Http 库通过查询字符串传递 public 键是否是个好主意?
我在 Xamarin Forms 上使用 Bouncy Castle 进行非对称加密。但我正在研究客户端 <-> Web Api 结构。如何将 public 密钥发送到另一端?因为类型是 RsaKeyParameters .
RsaKeyPairGenerator rsaKeyPairGnr = new RsaKeyPairGenerator();
rsaKeyPairGnr.Init(new KeyGenerationParameters(new SecureRandom(), 512));
AsymmetricCipherKeyPair keyPair = rsaKeyPairGnr.GenerateKeyPair();
RsaKeyParameters publicKey = (RsaKeyParameters)keyPair.Public;
如果我有 RsaKeyParameters publicKey
并且需要将其发送到服务器,我可以使用以下方式进行转换:
//convert from key to string
SubjectPublicKeyInfo publicKeyInfo = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(publicKey);
byte[] serializedPublicBytes = publicKeyInfo.ToAsn1Object().GetDerEncoded();
string serializedPublic = Convert.ToBase64String(serializedPublicBytes);
And then, i can convert the serializedPublic to RsaKeyParameters publicKey
//convert from string to key
RsaKeyParameters publicKey2 = (RsaKeyParameters)PublicKeyFactory.CreateKey(Convert.FromBase64String(serializedPublic));
但是有人可以告诉我通过 Http 库通过查询字符串传递 public 键是否是个好主意?