Skip to content

Instantly share code, notes, and snippets.

@VulBusters
Created August 9, 2023 07:56
Show Gist options
  • Save VulBusters/f5a39c2b6809e511737bd5cbdfcaba02 to your computer and use it in GitHub Desktop.
Save VulBusters/f5a39c2b6809e511737bd5cbdfcaba02 to your computer and use it in GitHub Desktop.
public static void KeyExchange()
{
String publicKeyPem = PlayerPrefs.GetString("clientPublicKey");
if(String.IsNullOrEmpty(publicKeyPem))
{
throw new PlayerPrefsItemNotFoundException("clientPublicKey");
}
String EcPublicKeyDerHexStr = EcPemtoDer(publicKeyPem, "public");
String serializedHttpBody = JsonConvert.SerializeObject(EcPublicKeyDerHexStr);
var (headers, jsonResponseText) = RequestHandler.Post("xxx.azurewebsites.com/api/KeyExchange"), null, false, serializedHttpBody);
KeyExchangeDto kexDto = new KeyExchangeDto();
try
{
kexDto = JsonConvert.DeserializeObject<KeyExchangeDto>(jsonResponseText);
}
catch(JsonSerializationException ex)
{
Debug.Log(ex.Message);
}
// the data that retrieve from the server
String keyId = kexDto.KeyId;
String salt = kexDto.Salt;
String serverPublicKey = kexDto.ServerPublicKey;
PlayerPrefs.SetString("keyId", keyId);
PlayerPrefs.SetString("salt", salt);
PlayerPrefs.SetString("serverPublicKey", serverPublicKey);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment