SetSeed() public method

public SetSeed ( byte inSeed ) : void
inSeed byte
return void
Exemplo n.º 1
0
        public static byte[] GetSeed(
            int length)
        {
            SecureRandom master = Master;

            master.SetSeed(DateTime.Now.Ticks);
            return(master.GenerateSeed(length));
        }
Exemplo n.º 2
0
        private static SecureString GenerateNewMachineKey(int keySize)
        {
            var random = new SecureRandom();
            random.SetSeed(random.GenerateSeed(128));

            var machineKeyString = "";
            for (var x = 0; x < keySize; x++)
            {
                machineKeyString += (char)random.Next(33, 126);
            }

            return machineKeyString.ConvertToSecureString();
        }
        private void RandMult(string label, X9ECParameters spec)
        {
            ECCurve C = spec.Curve;
            ECPoint G = (ECPoint)spec.G;
            BigInteger n = spec.N;

            SecureRandom random = new SecureRandom();
            random.SetSeed(DateTimeUtilities.CurrentUnixMs());

            Console.WriteLine(label);

            int[] coords = ECCurve.GetAllCoordinateSystems();
            for (int i = 0; i < coords.Length; ++i)
            {
                int coord = coords[i];
                if (C.SupportsCoordinateSystem(coord))
                {
                    ECCurve c = C;
                    ECPoint g = G;

                    bool defaultCoord = (c.CoordinateSystem == coord);
                    if (!defaultCoord)
                    {
                        c = C.Configure().SetCoordinateSystem(coord).Create();
                        g = c.ImportPoint(G);
                    }

                    double avgRate = RandMult(random, g, n);
                    string coordName = COORD_NAMES[coord];
                    StringBuilder sb = new StringBuilder();
                    sb.Append("   ");
                    sb.Append(defaultCoord ? '*' : ' ');
                    sb.Append(coordName);
                    for (int j = sb.Length; j < 30; ++j)
                    {
                        sb.Append(' ');
                    }
                    sb.Append(": ");
                    sb.Append(avgRate);
                    sb.Append(" mults/sec");
                    for (int j = sb.Length; j < 64; ++j)
                    {
                        sb.Append(' ');
                    }
                    sb.Append('(');
                    sb.Append(1000.0 / avgRate);
                    sb.Append(" millis/mult)");
                    Console.WriteLine(sb.ToString());
                }
            }
        }
Exemplo n.º 4
0
        public override void PerformTest()
        {
            SecureRandom    rand = new SecureRandom(new byte[20]);

            rand.SetSeed(DateTime.Now.Ticks);

            doTestPadding(new Pkcs7Padding(), rand,
                Hex.Decode("ffffff0505050505"),
                Hex.Decode("0000000004040404"));

            Pkcs7Padding padder = new Pkcs7Padding();
            try
            {
                padder.PadCount(new byte[8]);

                Fail("invalid padding not detected");
            }
            catch (InvalidCipherTextException e)
            {
                if (!"pad block corrupted".Equals(e.Message))
                {
                    Fail("wrong exception for corrupt padding: " + e);
                }
            }

            doTestPadding(new ISO10126d2Padding(), rand,
                null,
                null);

            doTestPadding(new X923Padding(), rand,
                null,
                null);

            doTestPadding(new TbcPadding(), rand,
                Hex.Decode("ffffff0000000000"),
                Hex.Decode("00000000ffffffff"));

            doTestPadding(new ZeroBytePadding(), rand,
                Hex.Decode("ffffff0000000000"),
                null);

            doTestPadding(new ISO7816d4Padding(), rand,
                Hex.Decode("ffffff8000000000"),
                Hex.Decode("0000000080000000"));
        }
		public void Test1000()
		{
			byte[] testData = new byte[10000];
			SecureRandom rand = new SecureRandom();

			rand.SetSeed(0);

			for (int i = 0; i != 10; i++)
			{
				CmsCompressedDataStreamGenerator gen = new CmsCompressedDataStreamGenerator();
				MemoryStream bOut = new MemoryStream();

				Stream cOut = gen.Open(bOut, CmsCompressedDataStreamGenerator.ZLib);

				rand.NextBytes(testData);

				cOut.Write(testData, 0, testData.Length);

				cOut.Close();

				CmsCompressedDataParser ed = new CmsCompressedDataParser(bOut.ToArray());

				Assert.IsTrue(Arrays.AreEqual(testData, CmsTestUtil.StreamToByteArray(ed.GetContent().ContentStream)));
			}
		}
Exemplo n.º 6
0
 private void RandomTests()
 {
     SecureRandom srng = new SecureRandom();
     srng.SetSeed(DateTimeUtilities.CurrentUnixMs());
     for (int i = 0; i < 10; ++i)
     {
         RandomTest(srng);
     }
 }
Exemplo n.º 7
0
 private void RandomTests()
 {
     SecureRandom srng = new SecureRandom();
     srng.SetSeed(DateTimeUtilities.CurrentUnixMs());
     RandomTests(srng, null);
     RandomTests(srng, new BasicGcmMultiplier());
     RandomTests(srng, new Tables8kGcmMultiplier());
     RandomTests(srng, new Tables64kGcmMultiplier());
 }