예제 #1
0
 public LoadModule()
 {
     SecureType            = AisSecureType.NONE;
     MagicNum              = SecureLoadMagic.LOADMOD_MAGIC;
     certRsaObject         = null;
     rsaObject             = null;
     certEncryptionKey     = null;
     customerEncryptionKey = null;
 }
예제 #2
0
        public LoadModule(AisSecureType secureType, SecureLoadMagic magic, String encKey, String rsaKeyFileName) : this()
        {
            String currHashAlgorithmString = "SHA1"; // Default hash algorithm

            SecureType = secureType;
            MagicNum   = magic;

            // Get the encryption key
            customerEncryptionKey = new Byte[16];
            CEKInitialValue       = new Byte[16];

            if (encKey.Length != 32)
            {
                throw new ArgumentException("AES Encryption Key is wrong length!");
            }
            for (int j = 0; j < encKey.Length; j += 2)
            {
                customerEncryptionKey[(j >> 1)] = Convert.ToByte(encKey.Substring(j, 2), 16);
            }

            // Generate IV as encrypted version of AES Key
            using (MemoryStream ms = new MemoryStream(CEKInitialValue))
            {
                Aes myAES = new AesManaged();
                myAES.KeySize = 128;
                myAES.Mode    = CipherMode.ECB;
                myAES.Padding = PaddingMode.None;
                ICryptoTransform encryptor = myAES.CreateEncryptor(customerEncryptionKey, new Byte[16]);
                CryptoStream     cs        = new CryptoStream(ms, encryptor, CryptoStreamMode.Write);
                cs.Write(customerEncryptionKey, 0, customerEncryptionKey.Length);
            }

            // Get RSA key
            rsaObject = RSAKey.LoadFromFile(rsaKeyFileName);
            if (rsaObject == null)
            {
                throw new ArgumentException("RSA key loading failed!");
            }

            // Update the hash algo string if RSA key size is 2048 bits
            if (rsaObject.KeySize == 2048)
            {
                currHashAlgorithmString = "SHA256";
                currHashAlgorithmValue  = SHA_Algorithm.SHA256;
            }

            try
            {
                currHashAlgorithm = HashAlgorithm.Create(currHashAlgorithmString);
            }
            catch (Exception e)
            {
                Console.WriteLine("Invalid Hash Algorithm Selected. Exception message: {0}.", e.Message);
                throw e;
            }
        }
예제 #3
0
        public LoadModule(AisSecureType secureType, SecureLoadMagic magic, String encKey, String rsaKeyFileName)
            : this()
        {
            String currHashAlgorithmString = "SHA1";  // Default hash algorithm

              SecureType = secureType;
              MagicNum = magic;

              // Get the encryption key
              customerEncryptionKey = new Byte[16];
              CEKInitialValue = new Byte[16];

              if (encKey.Length != 32)
              {
            throw new ArgumentException("AES Encryption Key is wrong length!");
              }
              for (int j=0; j<encKey.Length; j+=2)
              {
            customerEncryptionKey[(j>>1)] = Convert.ToByte(encKey.Substring(j,2),16);
              }

              // Generate IV as encrypted version of AES Key
              using (MemoryStream ms = new MemoryStream(CEKInitialValue))
              {
            Aes myAES = new AesManaged();
            myAES.KeySize = 128;
            myAES.Mode = CipherMode.ECB;
            myAES.Padding = PaddingMode.None;
            ICryptoTransform encryptor = myAES.CreateEncryptor(customerEncryptionKey, new Byte[16]);
            CryptoStream cs = new CryptoStream(ms,encryptor,CryptoStreamMode.Write);
            cs.Write(customerEncryptionKey,0,customerEncryptionKey.Length);
              }

              // Get RSA key
              rsaObject = RSAKey.LoadFromFile(rsaKeyFileName);
              if (rsaObject == null)
              {
            throw new ArgumentException("RSA key loading failed!");
              }

              // Update the hash algo string if RSA key size is 2048 bits
              if (rsaObject.KeySize == 2048)
              {
            currHashAlgorithmString = "SHA256";
            currHashAlgorithmValue = SHA_Algorithm.SHA256;
              }

              try
              {
            currHashAlgorithm = HashAlgorithm.Create(currHashAlgorithmString);
              }
              catch (Exception e)
              {
            Console.WriteLine("Invalid Hash Algorithm Selected. Exception message: {0}.",e.Message);
            throw e;
              }
        }
예제 #4
0
 public LoadModule(AisSecureType secureType, SecureLoadMagic magic)
     : this()
 {
     SecureType = secureType;
       MagicNum = magic;
 }
예제 #5
0
 public LoadModule()
 {
     SecureType = AisSecureType.NONE;
       MagicNum = SecureLoadMagic.LOADMOD_MAGIC;
       certRsaObject = null;
       rsaObject = null;
       certEncryptionKey = null;
       customerEncryptionKey = null;
 }
예제 #6
0
 public LoadModule(AisSecureType secureType, SecureLoadMagic magic) : this()
 {
     SecureType = secureType;
     MagicNum   = magic;
 }