Problème OJ 3492 Algorithme de cryptage symétrique DES

Description du titre

Reportez-vous à la documentation connexe et concevez un algorithme de cryptage symétrique DES. Et écrivez une application console pour vérifier. La clé est définie sur: @ 1234567. 
    class Program {  
        // Vérifier l'algorithme de chiffrement DES
        static void Main (string [] args) {             Console.WriteLine (Class1.ECP ("absg123 @ &!"));         }     }     public class Class1 {         // La fonction de méthode ECP suivante est algorithme de chiffrement symétrique adopté         // Le principe de cet algorithme, s'il vous plaît Baidu         const string KEY_64 = "@ 1234567";         const string IV_64 = "@ 1234567";         public static string ECP (string data) {               // Ecrire le code d'algorithme de chiffrement symétrique DES ici         }










Entrer

Un string

Sortir

Chaîne cryptée

Exemple d'entrée

123456

Exemple de sortie

czgzz5i20Rw =
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
using System.IO;
namespace ConsoleApplication1
{
    class Program
    {
        //验证DES加密算法
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            Console.WriteLine(Class1.ECP(input, "@1234567"));
        }
    }
    public class Class1
    {
        //下面ECP方法功能为采用对称加密算法
        //该算法原理请大家百度
        public static string ECP(string encryptString, string encryptKey)
        {
            try
            {
                byte[] rgbKey = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8));
                byte[] rgbIV = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8));
                byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString);
                DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider();
                MemoryStream mStream = new MemoryStream();
                CryptoStream cStream = new CryptoStream(mStream, dCSP.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
                cStream.Write(inputByteArray, 0, inputByteArray.Length);
                cStream.FlushFinalBlock();
                return Convert.ToBase64String(mStream.ToArray());
            }
            catch
            {
                return encryptString;
            }
        }
    }
}

Cette référence de blog: https://www.cnblogs.com/mjn1/p/12507850.html

Je ne comprends pas l'essence de l'algorithme de cryptage symétrique DEC

Je suppose que tu aimes

Origine blog.csdn.net/wangws_sb/article/details/104930686
conseillé
Classement