Example #1
0
        private void btnDecrypt_Click(object sender, EventArgs e)
        {
            // refresh the encryption strength (this doesn't seem to make any difference in the cipher)

            // to test inbound EncryptionLevel settings, convert the keysize to a byte to verify accurate and safe casting to
            // a CryptoStrength enum selection.
            byte estrength = Convert.ToByte(m_keySize);

            // retrieve the crypto configuration for this particular cipher:
            var response = Convert.FromBase64String(txtEncryptedText.Text);

            var storedToken = new RESTAuthToken();
            storedToken.RESTAuthTokenInfo = response;

            // decrypt the message (returned as a byte array)
            txtClearText.Text = storedToken.ClearText;
        }
Example #2
0
        private void btnEncrypt_Click(object sender, EventArgs e)
        {
            // refresh the encryption strength (this doesn't seem to make any difference in the cipher)
            setAesStrength();

            // Encrypt the string to an array of bytes.
            byte[] clearPayload = Encoding.ASCII.GetBytes(txtClearText.Text);
            CryptoManager.Crypto.ToJson = Convert.ToBase64String(CryptoManager.Crypto.EncryptAES(clearPayload, m_keySize));
            txtClearText.Text = CryptoManager.Crypto.ToJson;
            txtCryptoAESSalt.Text = CryptoManager.Crypto.CryptoSalt;
            txtNonceValue.Text = Encoding.ASCII.GetString(CryptoManager.Crypto.Nonce);

            var bson = Encoding.ASCII.GetBytes(CryptoManager.Crypto.ToJson);
            txtEncryptedText.Text = Convert.ToBase64String(bson);
            var json = Encoding.ASCII.GetString(Convert.FromBase64String(txtEncryptedText.Text));

            var token = new RESTAuthToken { RESTTransactionId = Guid.NewGuid(), RESTAuthTokenInfo = bson, RESTExpiration = DateTime.UtcNow.AddMinutes(60) };
        }