Beispiel #1
0
    // Takes a string for a key as input, encrypts it, and returns a byte[] of the encrypted key
    public byte[] encryptKey(string 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);
    }
Beispiel #2
0
    // To be finished at a later date
    public int[] testRandomSeedGenerator()
    {
        int[] passed = new int[2];
        passed[1] = 1;

        byte[] testSeed1 = new byte[10];
        byte[] testSeed2 = new byte[10];
        testSeed1 = OTPworker.randomSeedGenerator(testSeed1);
        testSeed2 = OTPworker.randomSeedGenerator(testSeed2);

        Debug.Log("RandomSeedGenerator() test passed");

        // if no errors have happened by here, the test has passed
        passed[0] = 1;
        return(passed);
    }
Beispiel #3
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);
    }
Beispiel #4
0
    void testRun2()
    {
        byte[] testRunSeed = new byte[14];
        testRunSeed = OTPworker.randomSeedGenerator(testRunSeed);

        if (testRunSeed[13] > 15)
        {
            testRunSeed[13] = (byte)((int)testRunSeed[13] % 7);
        }

        List <int> tempList = customList(3, 4, 2, 4, 4);

        BitArray seedBits = byteToBits(testRunSeed);

        int[] actions = bitConverter(seedBits, tempList);

        byte[] finalSeed = seed108Converter(actions, tempList);

        Debug.Log("Initial seed: " + byteToSeed(testRunSeed));
        Debug.Log("Final  seed: " + byteToSeed(finalSeed));
    }
Beispiel #5
0
    // Takes a key as input, encrypts the key, sends it to didery in a POST request
    public void demoEncryptKey(string inputKey)
    {
        int size = 32;

        string[] dideryData;

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

        seed = OTPworker.randomSeedGenerator(seed);
        seed = checkSeed(seed);

        // Used for demo puroses
        if (seed[13] > 7)
        {
            seed[13] = (byte)((int)seed[13] % 7);
        }
        //seed = HexStringToByteArray("4040C1A90886218984850151AC123249");

        OTPworker.OTPGenerator(otp, size, seed);

        encryptedKey = OTPworker.OTPxor(key, otp);

        dideryData = DideryInterface.makePost(encryptedKey);

        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);
    }
    public int[] testMultipleSizeSeeds()
    {
        int[] passed = new int[2];

        string testHex = "FFFFAAAAFFFFAAAAFFFFDDDDFFFF";

        byte[] testHexSeed = SeedToByte.HexStringToByteArray(testHex);
        byte[] testRunSeed = new byte[14];
        testRunSeed = OTPworker.randomSeedGenerator(testRunSeed);

        List <int> tempList1 = SeedToByte.customList(4, 4, 2, 4, 4);
        List <int> tempList2 = SeedToByte.customList(3, 4, 2, 4, 4);

        BitArray seedBits1 = seedToByte.byteToBits(testRunSeed);
        BitArray seedBits2 = seedToByte.byteToBits(testHexSeed);

        int[] actions1 = seedToByte.bitToActions(seedBits1, tempList1);
        int[] actions2 = seedToByte.bitToActions(seedBits2, tempList1);

        byte[] finalSeed1 = SeedToByte.seedConverterUniversal(actions1, tempList1);
        byte[] finalSeed2 = SeedToByte.seedConverterUniversal(actions2, tempList1);

        passed[1] += 1;
        if (seedToByte.byteToSeed(testRunSeed) == seedToByte.byteToSeed(finalSeed1))
        {
            passed[0] += 1;
        }
        else
        {
            Debug.Log("Test 1 for converting 112 bit seed to action list and back failed");
        }

        passed[1] += 1;
        if (seedToByte.byteToSeed(testHexSeed) == seedToByte.byteToSeed(finalSeed2))
        {
            passed[0] += 1;
        }
        else
        {
            Debug.Log("Test 2 for converting 112 bit seed to action list and back failed");
        }

        testHexSeed = new byte[14];
        testRunSeed = OTPworker.randomSeedGenerator(testRunSeed);

        if (testRunSeed[13] > 7)
        {
            testRunSeed[13] = (byte)((int)testRunSeed[13] % 7);
        }

        BitArray seedBits = seedToByte.byteToBits(testHexSeed);

        int[] actions3 = seedToByte.bitToActions(seedBits, tempList2);

        byte[] finalSeed3 = SeedToByte.seedConverterUniversal(actions3, tempList2);

        passed[1] += 1;
        if (seedToByte.byteToSeed(testHexSeed) == seedToByte.byteToSeed(finalSeed3))
        {
            passed[0] += 1;
        }
        else
        {
            Debug.Log("Test for converting 108 bit seed to action list and back failed");
        }

        return(passed);
    }