Exemplo n.º 1
0
    ///   <summary>
    ///   获得初始向量IV
    ///   </summary>
    ///   <returns> 初试向量IV </returns>
    private byte[] GetLegalIV()
    {
        string sTemp = IV;

        rc.GenerateIV();
        byte[] bytTemp  = rc.IV;
        int    IVLength = bytTemp.Length;

        if (sTemp.Length > IVLength)
        {
            sTemp = sTemp.Substring(0, IVLength);
        }
        else if (sTemp.Length < IVLength)
        {
            sTemp = sTemp.PadRight(IVLength, ' ');
        }
        return(ASCIIEncoding.ASCII.GetBytes(sTemp));
    }
Exemplo n.º 2
0
        private void encode_RC2_CBF_Click(object sender, EventArgs e)
        {
            DateTime then = DateTime.Now;
            String   Data = input7.Text;

            try
            {
                MemoryStream mStream = new MemoryStream();

                RC2 alg = RC2.Create();
                alg.GenerateKey();
                Key = alg.Key;
                alg.GenerateIV();
                IV = alg.IV;

                CryptoStream cStream = new CryptoStream(mStream,
                                                        alg.CreateEncryptor(Key, IV),
                                                        CryptoStreamMode.Write);

                byte[] toEncrypt = new ASCIIEncoding().GetBytes(Data);

                cStream.Write(toEncrypt, 0, toEncrypt.Length);
                cStream.FlushFinalBlock();

                byte[] ret = mStream.ToArray();

                cStream.Close();
                mStream.Close();

                cipherbytes = ret;
                input8.Text = Encoding.UTF8.GetString(cipherbytes);
                delta4.Text = (DateTime.Now - then).TotalSeconds.ToString() + " сек";
            }
            catch (CryptographicException ex)
            {
                Console.WriteLine("A Cryptographic error occurred: {0}", ex.Message);
                return;
            }
        }
Exemplo n.º 3
0
 public string CreateRC2IV()
 {
     rc2.GenerateIV();
     return(ByteToString(rc2.IV));
 }