Ejemplo n.º 1
0
    // Test that a valid key passes the key validation function - needs changes to
    //  OTPgenerator to work properly
    public int[] testGoodDecrypt()
    {
        int[] passed = new int[2];
        passed[1] = 1;

        string seed = "A021E0A80264A33C08B6C2884AC0685C";
        string key  = "0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7";

        key = VerifyKeys.removeHexPrefix(key);
        byte[] otp          = new byte[32];
        byte[] seedByte     = new byte[14];
        byte[] encryptedKey = new byte[34];
        byte[] keyByte      = Encoding.ASCII.GetBytes(key);
        seedByte = Encoding.ASCII.GetBytes(seed);
        byte[] goodKey      = OTPworker.OTPxor(seedByte, keyByte);
        byte[] decryptedKey = OTPworker.decryptFromBlob(seed, Convert.ToBase64String(goodKey));
        string finalKey     = Encoding.ASCII.GetString(keyByte);

        if (finalKey == key)
        {
            passed[0] = 1;
        }

        return(passed);
    }
Ejemplo n.º 2
0
    // Test the function to generate public address from private key
    public void testRegenerateAddress()
    {
        string privateKey = "0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7";
        string address    = VerifyKeys.regeneratePublicAddress(privateKey);

        Debug.Log("Your public address is: " + address);
    }
Ejemplo n.º 3
0
    // Takes an encrypted key, and a seed, returns a byte array of the the otp decrypted seed
    public static byte[] decryptKey(byte[] key, byte[] seed, int size = 32)
    {
        byte[] otp = new byte[32];

        OTPGenerator(otp, size, seed);
        key = OTPxor(key, otp);
        int valid = VerifyKeys.verifyKey(ByteArrayToHex(key));

        return(key);
    }
Ejemplo n.º 4
0
    // Decrypts the blob saved at DideryDemoManager.demoBlob
    public static byte[] decryptFromBlob(string seed, string blobString)
    {
        byte[] seedByte      = HexStringToByteArray(seed);
        byte[] demoBlob      = Convert.FromBase64String(blobString);
        byte[] decryptedKey  = decryptKey(demoBlob, seedByte);
        string decryptedBlob = ByteArrayToHex(decryptedKey);
        int    valid         = VerifyKeys.verifyKey(decryptedBlob);

        return(decryptedKey);
    }
Ejemplo n.º 5
0
    // Takes a string for a key as input, encrypts it, and returns a byte[] of the encrypted key
    public byte[] encryptKey(string inputKey)
    {
        inputKey = VerifyKeys.removeHexPrefix(inputKey);
        byte[] otp          = new byte[32];
        byte[] seed         = new byte[16];
        byte[] encryptedKey = new byte[34];
        byte[] key          = Encoding.ASCII.GetBytes(inputKey);

        int size = 32;

        seed = OTPworker.randomSeedGenerator(seed);
        OTPworker.OTPGenerator(otp, size, seed);
        encryptedKey = OTPworker.OTPxor(key, otp);

        return(encryptedKey);
    }
Ejemplo n.º 6
0
    // Test that a valid key passes the key validation function
    public void testGoodDecrypt()
    {
        string seed = "A021E0A80264A33C08B6C2884AC0685C";
        string key  = "0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7";

        key = VerifyKeys.removeHexPrefix(key);
        byte[] otp          = new byte[32];
        byte[] seedByte     = new byte[14];
        byte[] encryptedKey = new byte[34];
        byte[] keyByte      = Encoding.ASCII.GetBytes(key);
        seedByte = Encoding.ASCII.GetBytes(seed);
        byte[] goodKey      = OTPworker.OTPxor(seedByte, keyByte);
        byte[] decryptedKey = OTPworker.decryptFromBlob(seed, Convert.ToBase64String(goodKey));
        string finalKey     = Encoding.ASCII.GetString(keyByte);

        Debug.Log("Bad decrypted key: " + finalKey);
    }
Ejemplo n.º 7
0
    // Takes a key as input, encrypts the key, sends it to didery in a POST request
    public void demoEncryptKey(string inputKey, string url = null)
    {
        inputKey = VerifyKeys.removeHexPrefix(inputKey);
        if (url == null)
        {
            url = urlAddress;
        }
        int size = 32;

        string[] dideryData;

        byte[] otp = new byte[32];
        //byte[] seed = new byte[16]; // used for 128 bit seed
        byte[] seed         = new byte[14]; // used for 108 bit seed
        byte[] encryptedKey = new byte[34];
        byte[] key          = Encoding.ASCII.GetBytes(inputKey);

        seed = OTPworker.randomSeedGenerator(seed);

        // Used for demo puroses - required if trying to use 108 bit seed
        if (seed[13] > 7)
        {
            seed[13] = (byte)((int)seed[13] % 7);
        }

        OTPworker.OTPGenerator(otp, size, seed);

        encryptedKey = OTPworker.OTPxor(key, otp);

        dideryData = DideryInterface.makePost(encryptedKey, seed);

        string did       = dideryData[0];
        string signature = dideryData[1];
        string postBody  = dideryData[2];

        //Debug.Log("Did: " + did + " signature: " + " postBody: " + postBody);
        SeedManager.InputSeed     = OTPworker.ByteArrayToHex(seed);
        DideryDemoManager.DemoDid = did;
        Debug.Log("Did: " + DideryDemoManager.DemoDid);

        postRequest(url, postBody, signature);
    }
Ejemplo n.º 8
0
    // Test that a valid key passes the key validation function
    public int[] testValidKey()
    {
        int[] passed = new int[2];
        passed[1] = 1;

        string key = "0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7";

        passed[0] = VerifyKeys.verifyKey(key);

        if (passed[0] == 1)
        {
            Debug.Log("testValidKey() failed");
            passed[0] = 0;
        }
        else
        {
            passed[0] = 1;
        }

        return(passed);
    }
Ejemplo n.º 9
0
    // Test the function to generate public address from private key
    public int[] testRegenerateAddress()
    {
        int[] passed = new int[2];
        passed[1] = 1;

        string privateKey   = "0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7";
        string addressCheck = "0x12890D2cce102216644c59daE5baed380d84830c";
        string address      = VerifyKeys.regeneratePublicAddress(privateKey);

        //Debug.Log("Your public address is: " + address);

        if (address == addressCheck)
        {
            passed[0] = 1;
        }
        else
        {
            Debug.Log("testRegenerateAddress() failed.");
        }

        return(passed);
    }
Ejemplo n.º 10
0
    // Test that a valid key passes the key validation function
    public void testValidKey()
    {
        string key = "0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7";

        VerifyKeys.verifyKey(key);
    }