Init() public method

public Init ( KeyGenerationParameters parameters ) : void
parameters KeyGenerationParameters
return void
Beispiel #1
0
		static TspTestUtil()
		{
			rand = new SecureRandom();

			kpg = GeneratorUtilities.GetKeyPairGenerator("RSA");
			kpg.Init(new RsaKeyGenerationParameters(
				BigInteger.ValueOf(0x10001), rand, 1024, 25));

			desede128kg = GeneratorUtilities.GetKeyGenerator("DESEDE");
			desede128kg.Init(new KeyGenerationParameters(rand, 112));

			desede192kg = GeneratorUtilities.GetKeyGenerator("DESEDE");
			desede192kg.Init(new KeyGenerationParameters(rand, 168));

			rc240kg = GeneratorUtilities.GetKeyGenerator("RC2");
			rc240kg.Init(new KeyGenerationParameters(rand, 40));

			rc264kg = GeneratorUtilities.GetKeyGenerator("RC2");
			rc264kg.Init(new KeyGenerationParameters(rand, 64));

			rc2128kg = GeneratorUtilities.GetKeyGenerator("RC2");
			rc2128kg.Init(new KeyGenerationParameters(rand, 128));

			serialNumber = BigInteger.One;
		}
Beispiel #2
0
        public static byte[] GenerateKey()
        {
            SecureRandom sr = new SecureRandom();

            KeyGenerationParameters kgp = new KeyGenerationParameters(sr, keySize);

            CipherKeyGenerator kg = new CipherKeyGenerator();
            kg.Init(kgp);

            return kg.GenerateKey();
        }
Beispiel #3
0
        public static byte[] generateIV(bool zeros = false)
        {
            byte[] iv;
            if (!zeros)
            {
                CipherKeyGenerator keyGen = new CipherKeyGenerator();
                keyGen.Init(new KeyGenerationParameters(new SecureRandom(), BLOCK_SIZE << 3));
                iv = keyGen.GenerateKey();
            }
            else
            {
                iv = new byte[BLOCK_SIZE];
            }

            ////@todo delete this
            //System.Console.WriteLine("iv: {0}", BitConverter.ToString(iv));

            return iv;
        }
Beispiel #4
0
        public static void DecodePublicKey(byte[] data)
        {
            /*TcpClient Client = new TcpClient();
            Client.Connect(IPAddress.Parse("127.0.0.1"), 3128);
            BinaryWriter bwr = new BinaryWriter(Client.GetStream());
            bwr.Write((byte)1);
            bwr.Write(data, 0, 162);*/

            AsymmetricKeyParameter kp = PublicKeyFactory.CreateKey(data);
            Key = (RsaKeyParameters)kp;
            PublicKey = new byte[data.Length];
            data.CopyTo(PublicKey,0);

            //Console.WriteLine("Exponent: " + Key.Exponent + "\nModulus: " + Key.Modulus);

            CipherKeyGenerator keygen = new CipherKeyGenerator();
            keygen.Init(new KeyGenerationParameters(new SecureRandom(), 128));
            SecretKey = keygen.GenerateKey();
        }
Beispiel #5
0
        private void HandleEncryptionRequest(EncryptionRequestPacket packet)
        {
            if(Authorized)
                return;

            if (AuthorizationStatus.HasFlag(AuthorizationStatus.EncryprionEnabled))
            {
                var generator = new CipherKeyGenerator();
                generator.Init(new KeyGenerationParameters(new SecureRandom(), 16 * 8));
                var sharedKey = generator.GenerateKey();

                var pkcs = new PKCS1Signer(packet.PublicKey);
                var signedSecret = pkcs.SignData(sharedKey);
                var signedVerify = pkcs.SignData(packet.VerificationToken);

                SendPacket(new EncryptionResponsePacket { SharedSecret = signedSecret, VerificationToken = signedVerify });

                Stream.InitializeEncryption(sharedKey);

                SendPacket(new AuthorizationPasswordPacket { PasswordHash = Password.Hash });
            }
            else
                throw new SCONException("Encryption was not enabled!");
        }
Beispiel #6
0
		static CmsTestUtil()
		{
		    try
		    {
		        rand = new SecureRandom();

				aes192kg = GeneratorUtilities.GetKeyGenerator("AES");
				aes192kg.Init(new KeyGenerationParameters(rand, 192));

		        desede128kg = GeneratorUtilities.GetKeyGenerator("DESEDE");
				desede128kg.Init(new KeyGenerationParameters(rand, 112));

				desede192kg = GeneratorUtilities.GetKeyGenerator("DESEDE");
				desede192kg.Init(new KeyGenerationParameters(rand, 168));

				rc240kg = GeneratorUtilities.GetKeyGenerator("RC2");
				rc240kg.Init(new KeyGenerationParameters(rand, 40));

				rc264kg = GeneratorUtilities.GetKeyGenerator("RC2");
				rc264kg.Init(new KeyGenerationParameters(rand, 64));

				rc2128kg = GeneratorUtilities.GetKeyGenerator("RC2");
				rc2128kg.Init(new KeyGenerationParameters(rand, 128));

				aesKg = GeneratorUtilities.GetKeyGenerator("AES");

				seedKg = GeneratorUtilities.GetKeyGenerator("SEED");

				camelliaKg = GeneratorUtilities.GetKeyGenerator("Camellia");

				serialNumber = BigInteger.One;
		    }
		    catch (Exception ex)
		    {
		        throw new Exception(ex.ToString());
		    }
		}
        private void HandleEncryptionRequest(EncryptionRequestPacket packet)
        {
            var generator = new CipherKeyGenerator();
            generator.Init(new KeyGenerationParameters(new SecureRandom(), 16 * 8));
            var sharedKey = generator.GenerateKey();

            var pkcs = new PKCS1Signer(packet.PublicKey);
            var signedSecret = pkcs.SignData(sharedKey);
            var signedVerify = pkcs.SignData(packet.VerificationToken);

            SendPacketDirect(new EncryptionResponsePacket { SharedSecret = signedSecret, VerificationToken = signedVerify });

            Stream.InitializeEncryption(sharedKey);

            State |= JoinState.JoinedGame;
        }
Beispiel #8
0
        public static KeyParameter generateKey(int keySize)
        {
            // walidacja parametru keySize
            //@todo

            CipherKeyGenerator keyGen = new CipherKeyGenerator();
            keyGen.Init(new KeyGenerationParameters(new SecureRandom(), keySize));
            byte[] sessionKey = keyGen.GenerateKey();
            var param = generateKeyFromBytes(sessionKey);

            return param;
        }
 public static SecretKey GenerateAESPrivateKey()
 {
     CipherKeyGenerator var0 = new CipherKeyGenerator();
     var0.Init(new KeyGenerationParameters(new Org.BouncyCastle.Security.SecureRandom(), 128));
     return new SecretKeySpec(var0.GenerateKey(), "AES");
 }