public void AgentCreateDeviceSetRsaKey() { // generate RSA key pair RsaKeyGenerator generator = new RsaKeyGenerator(); RsaPrivateKey privateKey = generator.GeneratePrivateKey(2048); RsaPublicKey publicKey = generator.GeneratePublicKey(privateKey); // set RSA keys into a CreateDeviceRequest object CreateDeviceRequest request = new CreateDeviceRequest(); request.ClientRsaPrivateKey = privateKey; request.ClientRsaPublicKey = publicKey; }
/// <summary> /// Generate RSA private key. /// </summary> /// <param name="key"></param> /// <param name="keyFormat"></param> /// <returns></returns> public static RsaKey GeneratePublicKey(string key, RsaKeyFormat keyFormat = RsaKeyFormat.XML) => RsaKeyGenerator.GeneratePublicKey(key, keyFormat);
/// <summary> /// Generate RSA private key. /// </summary> /// <param name="keySize"></param> /// <param name="keyFormat"></param> /// <param name="keepingFormat"></param> /// <returns></returns> public static RsaKey GeneratePublicKey(RsaKeySize keySize, RsaKeyFormat keyFormat = RsaKeyFormat.XML, bool keepingFormat = false) => RsaKeyGenerator.GeneratePublicKey(keySize, keyFormat, keepingFormat);
public static IRSA CreateWithPublicKey(string key, RsaKeyFormat keyFormat) => new RsaFunction(RsaKeyGenerator.GeneratePublicKey(key, keyFormat));