private static IPublicKey GeneratePublicKey(string encodedPublicKey)
{
try
{
byte[] decodedKey = Convert.FromBase64String(encodedPublicKey);
KeyFactory keyFactory = KeyFactory.GetInstance(KEY_FACTORY_ALGORITHM);
return keyFactory.GeneratePublic(new X509EncodedKeySpec(decodedKey));
}
catch (NoSuchAlgorithmException e)
{
// This won't happen in an Android-compatible environment.
throw new RuntimeException(e);
}
catch (FormatException e)
{
Log.Error(TAG, "Could not decode from Base64.");
throw e;
}
catch (InvalidKeySpecException e)
{
Log.Error(TAG, "Invalid key specification.");
throw new IllegalArgumentException(e);
}
}