private void InternalWriteLicense(string filePath, string netsealId, LicenseFile licenseFile, FileAttributes attributes)
{
using (var memoryStream = new MemoryStream())
{
using (var binaryWriter = new BinaryWriter(memoryStream))
{
binaryWriter.Write(licenseFile.GUID);
binaryWriter.Write(licenseFile.Unknown);
binaryWriter.Write(licenseFile.Remember);
if (licenseFile.Remember)
{
binaryWriter.Write(licenseFile.Username);
binaryWriter.Write(licenseFile.Sha1Password);
}
}
byte[] derivation = null;
if (licenseFile.Framework == LicenseFramework.Framework2_0)
derivation = GetDerivationFr2_0(netsealId);
else if (licenseFile.Framework == LicenseFramework.Framework4_5)
derivation = GetDerivationFr4_5(netsealId);
else
throw new Exception("License Framework");
var encrypted = EncryptLicense(memoryStream.ToArray(), derivation);
if (attributes == 0)
attributes = FileAttributes.Hidden | FileAttributes.NotContentIndexed | FileAttributes.ReadOnly | FileAttributes.System;
if (File.Exists(filePath))
File.SetAttributes(filePath, FileAttributes.Normal);
File.WriteAllBytes(filePath, encrypted);
File.SetAttributes(filePath, attributes);
}
}