Пример #1
0
        public async Task <CNG> DencryptAsync(Stream encryptedStream, Byte[] iv, Byte[] bkey)
        {
            CNG cng = new CNG();

            cng.Key    = bkey;
            cng.Iv     = iv;
            cng.Stream = encryptedStream;
            return(await Task.Factory.StartNew(() =>
            {
                using (Aes aes = new AesCryptoServiceProvider())
                {
                    aes.Key = cng.Key;
                    aes.IV = cng.Iv;
                    aes.Padding = PaddingMode.PKCS7;
                    // Decrypt the message
                    using (MemoryStream plaintext = new MemoryStream())
                    {
                        using (CryptoStream cs = new CryptoStream(plaintext, aes.CreateDecryptor(), CryptoStreamMode.Write))
                        {
                            encryptedStream.CopyTo(cs);
                            cs.Close();
                            cng.PlaintextBytes = plaintext.ToArray();
                        }
                    }
                }
                return cng;
            }));
        }
Пример #2
0
 public CNG Decrypt(CNG c)
 {
     DecryptMessage(out c.PlaintextBytes, c.EncryptedBytes, c.Iv, c.Key);
     c.EncryptedBytes = null;
     c.Iv             = null;
     return(c);
 }
Пример #3
0
        public async Task <CNG> EncryptAsync(Byte[] key, Stream plaintextMessage)
        {
            CNG cng = new CNG();

            cng.Key    = key;
            cng.Stream = plaintextMessage;
            return(await Task.Factory.StartNew(() =>
            {
                using (Aes aes = new AesCryptoServiceProvider())
                {
                    aes.Key = key;
                    cng.Iv = aes.IV;
                    aes.Padding = PaddingMode.PKCS7;
                    using (MemoryStream ciphertext = new MemoryStream())
                    {
                        using (CryptoStream cs = new CryptoStream(ciphertext, aes.CreateEncryptor(), CryptoStreamMode.Write))
                        {
                            plaintextMessage.CopyTo(cs);
                            cs.Close();
                            cng.EncryptedBytes = ciphertext.ToArray();
                        }
                    }
                    return cng;
                }
            }));
        }
Пример #4
0
        public CNG B(CNG c)
        {
            c.Alice.P_G      = c.Bob.P_G = DiffieHellman.GetTwoCryptoPrimes();
            c.Bob.PrivateKey = DiffieHellman.PrivateKey(c.Bob.P_G.Item1);
            c.Bob.PublicKey  = DiffieHellman.PublicKey(c.Bob.P_G.Item1, c.Bob.P_G.Item2, c.Bob.PrivateKey);
            if (c.Alice.PublicKey != null)
            {
                c.Bob.Key = c.Alice.Key = DiffieHellman.Secret(c.Bob.P_G.Item1, c.Alice.PublicKey, c.Bob.PrivateKey);
            }


            return(c);
        }
Пример #5
0
        public CNG A(CNG c)
        {
            //alice creates a public and private key
            c.Alice.P_G        = c.Bob.P_G = DiffieHellman.GetTwoCryptoPrimes();
            c.Alice.PrivateKey = DiffieHellman.PrivateKey(c.Alice.P_G.Item1);
            c.Alice.PublicKey  = DiffieHellman.PublicKey(c.Alice.P_G.Item1, c.Alice.P_G.Item2, c.Alice.PrivateKey);
            //check if bob has supplied public key yet
            if (c.Bob.PublicKey != null)
            {
                c.Bob.Key = c.Alice.Key = DiffieHellman.Secret(c.Alice.P_G.Item1, c.Bob.PublicKey, c.Alice.PrivateKey);
            }

            return(c);
        }
Пример #6
0
    void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }

        if (this.dontDestroy)
        {
            DontDestroyOnLoad(gameObject);
        }
    }
Пример #7
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                var salty = ECDHAES256s.AES.GetSalt();
                var id    = context.Request.Path.TrimStart('/').Split(new string[] { ".key" }, StringSplitOptions.None)[0];

                var pk  = context.Request.QueryString["pk"];
                var cng = new CNG(HttpServerUtility.UrlTokenDecode(pk));
                cng = DH.B(cng); //MAKE KEY

                context.Application[id + "pass"] = Convert.ToBase64String(cng.Key);
                context.Response.ContentType     = "text/plain";
                context.Response.Write(HttpServerUtility.UrlTokenEncode(cng.PublicKey));
            }
            catch
            {
                context.Response.ContentType = "text/plain";
                context.Response.Write("error");
            }
        }
Пример #8
0
        /****************/
        /* Decode frame */
        /****************/
        internal int silk_decode_frame(
            EntropyCoder psRangeDec,           /* I/O  Compressor data structure                   */
            short[] pOut,                      /* O    Pointer to output speech frame              */
            int pOut_ptr,
            BoxedValueInt pN,                  /* O    Pointer to size of output frame             */
            int lostFlag,                      /* I    0: no loss, 1 loss, 2 decode fec            */
            int condCoding                     /* I    The type of conditional coding to use       */
            )
        {
            SilkDecoderControl thisCtrl = new SilkDecoderControl();
            int L, mv_len, ret = 0;

            L = this.frame_length;
            thisCtrl.LTP_scale_Q14 = 0;

            /* Safety checks */
            Inlines.OpusAssert(L > 0 && L <= SilkConstants.MAX_FRAME_LENGTH);

            if (lostFlag == DecoderAPIFlag.FLAG_DECODE_NORMAL ||
                (lostFlag == DecoderAPIFlag.FLAG_DECODE_LBRR && this.LBRR_flags[this.nFramesDecoded] == 1))
            {
                short[] pulses = new short[(L + SilkConstants.SHELL_CODEC_FRAME_LENGTH - 1) & ~(SilkConstants.SHELL_CODEC_FRAME_LENGTH - 1)];
                /*********************************************/
                /* Decode quantization indices of side info  */
                /*********************************************/
                DecodeIndices.silk_decode_indices(this, psRangeDec, this.nFramesDecoded, lostFlag, condCoding);

                /*********************************************/
                /* Decode quantization indices of excitation */
                /*********************************************/
                DecodePulses.silk_decode_pulses(psRangeDec, pulses, this.indices.signalType,
                                                this.indices.quantOffsetType, this.frame_length);

                /********************************************/
                /* Decode parameters and pulse signal       */
                /********************************************/
                DecodeParameters.silk_decode_parameters(this, thisCtrl, condCoding);

                /********************************************************/
                /* Run inverse NSQ                                      */
                /********************************************************/
                DecodeCore.silk_decode_core(this, thisCtrl, pOut, pOut_ptr, pulses);

                /********************************************************/
                /* Update PLC state                                     */
                /********************************************************/
                PLC.silk_PLC(this, thisCtrl, pOut, pOut_ptr, 0);

                this.lossCnt        = 0;
                this.prevSignalType = this.indices.signalType;
                Inlines.OpusAssert(this.prevSignalType >= 0 && this.prevSignalType <= 2);

                /* A frame has been decoded without errors */
                this.first_frame_after_reset = 0;
            }
            else
            {
                /* Handle packet loss by extrapolation */
                PLC.silk_PLC(this, thisCtrl, pOut, pOut_ptr, 1);
            }

            /*************************/
            /* Update output buffer. */
            /*************************/
            Inlines.OpusAssert(this.ltp_mem_length >= this.frame_length);
            mv_len = this.ltp_mem_length - this.frame_length;
            Arrays.MemMoveShort(this.outBuf, this.frame_length, 0, mv_len);
            Array.Copy(pOut, pOut_ptr, this.outBuf, mv_len, this.frame_length);

            /************************************************/
            /* Comfort noise generation / estimation        */
            /************************************************/
            CNG.silk_CNG(this, thisCtrl, pOut, pOut_ptr, L);

            /****************************************************************/
            /* Ensure smooth connection of extrapolated and good frames     */
            /****************************************************************/
            PLC.silk_PLC_glue_frames(this, pOut, pOut_ptr, L);

            /* Update some decoder state variables */
            this.lagPrev = thisCtrl.pitchL[this.nb_subfr - 1];

            /* Set output frame length */
            pN.Val = L;

            return(ret);
        }
Пример #9
0
 public CNG Encrypt(CNG c)
 {
     EncryptMessage(c.Key, c.PlaintextBytes, out c.EncryptedBytes, out c.Iv);
     c.PlaintextBytes = null;
     return(c);
 }
Пример #10
0
        public AES()
        {
            CNG c = new CNG();

            Cng = c;
        }