Пример #1
0
        public static string NOMBRE_GRUPO = "group";          //grupo de la llave

        static void Main(string[] args)
        {
            //Conectarse al HSM
            Cxi cxi = new Cxi(HSM);

            Console.WriteLine("Conectado a HSM " + HSM);

            //Iniciar sesion
            cxi.Logon(USUARIO, CONTRASENA);
            Console.WriteLine("Usuario inicio sesion " + USUARIO);

            //Crear objeto Key Properties para buscar la llave, si no tiene specifier por defecto es -1
            KeyProperties kp = new KeyProperties(NOMBRE_LLAVE, NOMBRE_GRUPO);

            byte[] llave = cxi.findKey(0, kp);
            Console.WriteLine("Llave encontrada " + NOMBRE_LLAVE);

            //Generacion del mecanismo para encriptar y la encriptacion con llave AES
            MechParam mech = new MechParam(Cxi.MECH_MODE_ENCRYPT | Cxi.MECH_CHAIN_CBC | Cxi.MECH_PAD_PKCS5);

            byte[] datos = Encoding.UTF8.GetBytes("Cega Security");
            byte[] crypt = cxi.crypt(llave, mech, datos);
            Console.WriteLine("Datos cifrados " + Convert.ToBase64String(crypt));

            //Generacion del mecanismo para desencriptar y la desencriptacion con llave AES
            MechParam mechDecrypt = new MechParam(Cxi.MECH_MODE_DECRYPT | Cxi.MECH_CHAIN_CBC | Cxi.MECH_PAD_PKCS5);

            byte[] decrypt = cxi.crypt(llave, mechDecrypt, crypt);
            Console.WriteLine("Datos descifrados " + Encoding.UTF8.GetString(decrypt));

            cxi.Close();

            Console.ReadLine();
        }
Пример #2
0
        public static string NOMBRE_GRUPO = "group";          //grupo de la llave

        static void Main(string[] args)
        {
            //Conectarse al HSM
            Cxi cxi = new Cxi(HSM);

            Console.WriteLine("Conectado a HSM " + HSM);

            //Iniciar sesion
            cxi.Logon(USUARIO, CONTRASENA);
            Console.WriteLine("Usuario inicio sesion " + USUARIO);

            //Crear objeto Key Properties para buscar la llave, si no tiene specifier por defecto es -1
            KeyProperties kp = new KeyProperties(NOMBRE_LLAVE, NOMBRE_GRUPO);

            byte[] llave = cxi.findKey(0, kp);
            Console.WriteLine("Llave encontrada " + NOMBRE_LLAVE);

            //Creacion del HASH para la firma con SHA 256
            string datos = "Cega Security";

            byte[] hash = cxi.createHash(Cxi.MECH_HASH_ALGO_SHA256, datos);

            //Generacion del mecanismo para firmar y la firma con llave RSA
            MechParam mech = new MechParam(Cxi.MECH_HASH_ALGO_SHA256 | Cxi.MECH_PAD_PKCS1);

            byte[] sign = cxi.sign(0, llave, mech, hash);
            Console.WriteLine("Datos firmados " + Convert.ToBase64String(sign));

            //Verificacion de la firma
            bool verify = cxi.verify(0, llave, mech, hash, sign);

            Console.WriteLine("La verificacion es " + verify);

            cxi.Close();

            Console.ReadLine();
        }