SimpleParseASN1() public static method

public static SimpleParseASN1 ( string publicKey, byte &modulus, byte &exponent ) : void
publicKey string
modulus byte
exponent byte
return void
Ejemplo n.º 1
0
    void Start()
    {
        // Either parse the ASN1-formatted public LVL key at runtime (only available when stripping is disabled)..
        RSA.SimpleParseASN1(m_PublicKey_Base64, ref m_PublicKey.Modulus, ref m_PublicKey.Exponent);
        m_PublicKey_Modulus_Base64  = System.Convert.ToBase64String(m_PublicKey.Modulus);
        m_PublicKey_Exponent_Base64 = System.Convert.ToBase64String(m_PublicKey.Exponent);
        // .. and check the logcat for these values ...
        Debug.Log("private string m_PublicKey_Modulus_Base64 = \"" + m_PublicKey_Modulus_Base64 + "\";");
        Debug.Log("private string m_PublicKey_Exponent_Base64 = \"" + m_PublicKey_Exponent_Base64 + "\";");

        // .. or use pre-parsed keys (and remove the code above).
        m_PublicKey.Modulus  = System.Convert.FromBase64String(m_PublicKey_Modulus_Base64);
        m_PublicKey.Exponent = System.Convert.FromBase64String(m_PublicKey_Exponent_Base64);

        m_RunningOnAndroid = new AndroidJavaClass("android.os.Build").GetRawClass() != System.IntPtr.Zero;
        if (!m_RunningOnAndroid)
        {
            return;
        }

        LoadServiceBinder();

        new SHA1CryptoServiceProvider();                // keep a dummy reference to prevent too aggressive stripping

        m_ButtonMessage = "Check LVL";
    }
Ejemplo n.º 2
0
    private void OnValidate()
    {
        if (string.IsNullOrEmpty(m_PublicKey_Base64) == false)
        {
            try
            {
                RSA.SimpleParseASN1(m_PublicKey_Base64, ref m_PublicKey.Modulus, ref m_PublicKey.Exponent);
            }
            catch (Exception e)
            {
                Debug.LogError($"Please input a valid LVL public key in the inspector to generate its modulus and exponent\n{e.Message}");
                return;
            }

            // The reason we keep the modulus and exponent is to avoid a costly call to SimpleParseASN1 at runtime
            m_PublicKey_Modulus_Base64  = Convert.ToBase64String(m_PublicKey.Modulus);
            m_PublicKey_Exponent_Base64 = Convert.ToBase64String(m_PublicKey.Exponent);
            m_PublicKey_Base64          = string.Empty;
        }

        button = GetComponent <Button>();
    }