Example #1
0
        public void Test_Function()
        {
            SHA256Managed hash         = new SHA256Managed();
            SecureRandom  randomNumber = new SecureRandom();

            byte[]       encodingParam = hash.ComputeHash(Encoding.UTF8.GetBytes(randomNumber.ToString()));
            string       inputMessage  = "Test Message";
            UTF8Encoding utf8enc       = new UTF8Encoding();


            byte[] inputBytes = utf8enc.GetBytes(inputMessage);


            RsaKeyPairGenerator rsaKeyPairGnr = new RsaKeyPairGenerator();

            rsaKeyPairGnr.Init(new Org.BouncyCastle.Crypto.KeyGenerationParameters(new SecureRandom(), 1024));
            AsymmetricCipherKeyPair keyPair = rsaKeyPairGnr.GenerateKeyPair();

            publicKey  = (RsaKeyParameters)keyPair.Public;
            privateKey = (RsaKeyParameters)keyPair.Private;
            //string pub = GetPublicKey();
            //string priv = GetPrivateKey();
            IAsymmetricBlockCipher cipher = new OaepEncoding(new RsaEngine(), new Sha256Digest(), encodingParam);

            cipher.Init(true, publicKey);
            byte[] ciphered     = cipher.ProcessBlock(inputBytes, 0, inputMessage.Length);
            string cipheredText = utf8enc.GetString(ciphered);


            cipher.Init(false, privateKey);
            byte[] deciphered     = cipher.ProcessBlock(ciphered, 0, ciphered.Length);
            string decipheredText = utf8enc.GetString(deciphered);
        }
Example #2
0
 private void GeneratePair()
 {
     byte[] encodingParam = hash.ComputeHash(Encoding.UTF8.GetBytes(randomNumber.ToString()));
     keyPair    = rsaKeyPairGnr.GenerateKeyPair();
     publicKey  = (RsaKeyParameters)keyPair.Public;
     privateKey = (RsaKeyParameters)keyPair.Private;
     cipher     = new OaepEncoding(new RsaEngine(), new Sha256Digest(), encodingParam);
 }
Example #3
0
        public override async Task RunAsync(LocalizationService lcs)
        {
            this.Started = true;

            int num = new SecureRandom().Next(1000);

            await this.Channel.EmbedAsync(num.ToString(), Emojis.ArrowUp);

            while (this.participants.Any())
            {
                int guess = 0;
                InteractivityResult <DiscordMessage> mctx = await this.Interactivity.WaitForMessageAsync(
                    xm => {
                    if (xm.Channel.Id != this.Channel.Id || xm.Author.IsBot)
                    {
                        return(false);
                    }
                    if (!this.participants.Contains(xm.Author))
                    {
                        return(false);
                    }
                    return(int.TryParse(xm.Content, out guess));
                },
                    TimeSpan.FromSeconds(20)
                    );

                if (mctx.TimedOut)
                {
                    this.IsTimeoutReached = true;
                    return;
                }
                else if (guess == num + 1)
                {
                    num++;
                    this.Winner = mctx.Result.Author;
                }
                else
                {
                    await this.Channel.LocalizedEmbedAsync(lcs, Emojis.Dead, null, "fmt-game-nr-lost", mctx.Result.Author.Mention);

                    if (this.Winner is { } && this.Winner.Id == mctx.Result.Author.Id)