コード例 #1
0
ファイル: UnityCryptoManager.cs プロジェクト: Amitkapadi/WISP
        /// <summary>
        /// Decrypts the target key with the CryptoManager's private RSA key.  It is assumbed that the
        /// @rijKey was previously encrypted with the CryptoManager's public key.
        /// </summary>
        /// <param name="rijKey"></param>
        /// <returns></returns>
        public byte[] DecryptRijndaelKey(byte[] rijKey)
        {
            byte[] key = new byte[0];
            lock (this)
            {
                m_RSA = new RiaWebSoftRu.Cryptography.Crypto.RsaManaged();
                m_RSA.FromXmlString(System.Text.UTF8Encoding.UTF8.GetString(m_PrivateKey));
                m_RSA.Decrypt(rijKey, false);
            }

            return(key);
        }
コード例 #2
0
ファイル: UnityCryptoManager.cs プロジェクト: Amitkapadi/WISP
        /// <summary>
        /// Verifies the signature that was previously signed using the @publicKey's matching public key
        /// </summary>
        public bool VerifySignedHashSHA256(string publicKey, byte[] DataToVerify, byte[] SignedData)
        {
            try
            {
                // Verify the data using the signature.  Pass a new instance of SHA1CryptoServiceProvider
                // to specify the use of SHA1 for hashing.
                m_RSA.FromXmlString(publicKey);
                return(m_RSA.VerifyData(DataToVerify, m_SHA, SignedData));
            }
            catch (CryptographicException e)
            {
                Console.WriteLine(e.Message);

                return(false);
            }
        }
コード例 #3
0
ファイル: UnityCryptoManager.cs プロジェクト: kamilion/WISP
        /// <summary>
        /// Encrypts the target @rijKey with the given RSA public key.  Generally, the public RSA key is
        /// transmitted via plaintext and then used to encrypt the Rijndael key.  The encrypted Rijndael key can then
        /// only be decrypted by the holder of the private RSA key that was generated along with the public key.
        /// This is the core of the encryption key exchange at the beginning of all Kronus network communication.
        /// </summary>
        /// <param name="publicKey">the public RSA key used to encrpt @rijKey</param>
        /// <param name="rijKey">the Rijndael key to encrypt</param>
        /// <returns></returns>
        public byte[] EncryptRijndaelKey(byte[] publicKey, byte[] rijKey)
        {
            byte[] key = new byte[0];

            lock (this)
            {
                m_RSA = new RiaWebSoftRu.Cryptography.Crypto.RsaManaged();
                m_RSA.FromXmlString(System.Text.UTF8Encoding.UTF8.GetString(publicKey));
                key = m_RSA.Encrypt(rijKey, false);
            }

            return key;
        }