Error when load the decrypted license into a stream and set the license

I’m trying load the decrypted license (.txt file) into a stream and set the license.

But i get error: System.Xml.XmlException: ‘Data at the root level is invalid. Line 1, position 1.’

  • Detail error:

System.Xml.XmlException
HResult=0x80131940
Message=Data at the root level is invalid. Line 1, position 1.
Source=System.Xml
StackTrace:
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at System.Xml.XmlDocument.Load(Stream inStream)
— End of stack trace from previous location —
at  .(Object )
at  .(MethodBase , Boolean )
at  .( )
at  . ( ,  )
at  .()
at  .(Boolean )
— End of stack trace from previous location —
at  .(Object )
at  .()
at  .(Object , UInt32 )
at  .(Boolean )
at  .(Object[] , Type[] , Type[] , Object[] )
at  .(Int32 , Type[] , Type[] , Boolean )
at  .( ,  )
at  .()
at  .(Boolean )
— End of stack trace from previous location —
at  .(Object )
at  .()
at  .(Object , UInt32 )
at  .(Boolean )
at  .(Object[] , Type[] , Type[] , Object[] )
at  .(Stream , String[] )
at  .( ,  )
— End of stack trace from previous location —
at  .(Object )
at  .(MethodBase , Boolean )
at  .( )
at  . ( ,  )
at  .()
at  .(Boolean )
— End of stack trace from previous location —
at  .(Object )
at  . ( ,  )
at  .()
at  .(Boolean )
— End of stack trace from previous location —
at  .(Object )
at  .()
at  .(Object , UInt32 )
at  .(Boolean )
at  .(Boolean )
at  .(Object[] , Type[] , Type[] , Object[] )
at  .(Int32 , Type[] , Type[] , Boolean )
at  .( ,  )
at  .()
at  .(Boolean )
— End of stack trace from previous location —
at  .(Object )
at  .()
at  . ( ,  )
at  .()
at  .(Boolean )
— End of stack trace from previous location —
at  .(Object )
at  .()
at  .(Object , UInt32 )
at  .(Boolean )
at  .(Boolean )
at  .(Object[] , Type[] , Type[] , Object[] )
at GroupDocs.Comparison.License.SetLicense(Stream licenseStream)
at Program.Main(String[] args) in C:\Users\trucnv\source\repos\ConsoleApp_GroupDocs\ConsoleApp_GroupDocs\Program.cs:line 68

  • This is my code:

using GroupDocs.Comparison;
using System;
using System.IO;
using Microsoft.Office.Interop.Word;
using GroupDocs.Comparison.Options;
using System.Security.Cryptography;

internal class Program
{
public static byte[] EncryptDecryptLicense(byte[] licBytes, byte[] key)
{
byte[] output = new byte[licBytes.Length];

    for (int i = 0; i < licBytes.Length; i++)
        output[i] = Convert.ToByte(licBytes[i] ^ key[i]);

    return output;
}

public static byte[] GenerateKey(long size)
{
    RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
    byte[] strongBytes = new Byte[size];
    rng.GetBytes(strongBytes);

    return strongBytes;
}


static void Main(string[] args)
{

    string encryptedFilePath = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "EncryptedLicense.txt");
    Console.WriteLine("licensePath: {0}.", encryptedFilePath);


    int keySize = 1007;
    byte[] key = GenerateKey(keySize);

  
    byte[] decryptedLicense;
    decryptedLicense = EncryptDecryptLicense(File.ReadAllBytes(encryptedFilePath), key);

 
    MemoryStream licenseStream = new MemoryStream(decryptedLicense);

    License license = new License();
    license.SetLicense(licenseStream);

    using (Comparer comparer = new Comparer(@"C:\Users\trucnv\Downloads\Shape\source.docx"))
    {
        comparer.Add(@"C:\Users\trucnv\Downloads\Shape\target.docx");

        CompareOptions compareOptions = new CompareOptions()
        {
            MarkChangedContent = true,
            DetectStyleChanges = true,
            ChangedItemStyle = new StyleSettings()
            {
                FontColor = System.Drawing.Color.Yellow,
                IsUnderline = true,
                //HighlightColor = System.Drawing.Color.Yellow,
            },
            InsertedItemStyle = new StyleSettings()
            {
                FontColor = System.Drawing.Color.Blue,
                IsUnderline = true,
            },
            DeletedItemStyle = new StyleSettings()
            {
                FontColor = System.Drawing.Color.Red,
                IsStrikethrough = true,
            },
        };
        comparer.Compare("C:\\Users\\trucnv\\Downloads\\CompareWord\\Data_Sample\\output\\o1.docx", compareOptions);

    }
    Console.WriteLine($"Donee");
}

}

Please help me. I want to package my project with your license.

Thank you!!!

@FPT008
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): COMPARISONNET-3916

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@FPT008

Looks like the issue is not in Comparison API itself but in the encryption process.
We tried to reproduce the issue using the provided code and found that the exception only occurs when the encrypted license is set. Once we decrypt the license, the comparison functions correctly. It’s possible that your license was not decrypted properly. Please ensure that the license remains intact after the decryption process.