public LoadModule() { SecureType = AisSecureType.NONE; MagicNum = SecureLoadMagic.LOADMOD_MAGIC; certRsaObject = null; rsaObject = null; certEncryptionKey = null; customerEncryptionKey = null; }
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; } }
// Public Constructor public AIS_Parser(AisHostType hostType, AisSecureType secType, LogFxnDelegate hostLogFxn, ReadFxnDelegate hostReadFxn, WriteFxnDelegate hostWriteFxn) { // apply specified params this.hostDevice = hostType; this.readFxn = hostReadFxn; this.writeFxn = hostWriteFxn; this.logFxn = hostLogFxn; this.secureType = secType; // use defaults for others posN = 2; ioBits = 8; ioDelay = 0; opcodeDelay = 5; ioTimeout = 5000; // 5s waitBOOTME = true; if (secureType == AisSecureType.GENERIC) { sigSize = 32; } else if (secureType == AisSecureType.CUSTOM) { sigSize = 128; // default to RSA1024 to start } else { sigSize = 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; } }
public LoadModule(AisSecureType secureType, SecureLoadMagic magic) : this() { SecureType = secureType; MagicNum = magic; }