Beispiel #1
0
        /// <summary>
        /// Generates the link key from the specified Installation Code
        /// </summary>
        /// <param name="installationCode">The installation Code</param>
        /// <returns>The resulting Link Key</returns>
        //  Revision History
        //  MM/DD/YY Who Version Issue# Description
        //  -------- --- ------- ------ -------------------------------------------
        //  08/30/11 RCG 2.52.10        Created

        public static byte[] GenerateLinkKey(byte[] installationCode)
        {
            byte[] LinkKey = null;

            if (installationCode != null)
            {
                switch (installationCode.Length)
                {
                case 8:
                case 10:
                case 14:
                case 18:
                {
                    CrcHelper CrcHelper = new CrcHelper(CrcAlgorithmType.Crc16Ccitt);
                    ushort    CRC       = (ushort)(installationCode[installationCode.Length - 2] + (installationCode[installationCode.Length - 1] << 8));
                    byte[]    Code      = new byte[installationCode.Length - 2];

                    Array.Copy(installationCode, Code, Code.Length);

                    // Validate the CRC
                    if (CRC == CrcHelper.CalculateCrc(Code))
                    {
                        LinkKey = MMOHash(Code);
                    }
                    else
                    {
                        throw new ArgumentException("The provided installation code has an invalid CRC.", "installationCode");
                    }

                    break;
                }

                default:
                {
                    throw new ArgumentException("The provided installation code is invalid.", "installationCode");
                }
                }
            }
            else
            {
                throw new ArgumentNullException("installationCode", "The Installation Code may not be null");
            }

            return(LinkKey);
        }
Beispiel #2
0
        /// <summary>
        /// Generates a new Install Code with the specified length
        /// </summary>
        /// <param name="size">The size of the Install Code to generate</param>
        /// <returns>The new install code</returns>
        //  Revision History
        //  MM/DD/YY Who Version Issue# Description
        //  -------- --- ------- ------ -------------------------------------------
        //  08/30/11 RCG 2.52.10        Created

        public static byte[] GenerateInstallCode(InstallCodeSize size)
        {
            RNGCryptoServiceProvider RandomGenerator = new RNGCryptoServiceProvider();

            byte[]    NewCode     = new byte[(int)size];
            byte[]    InstallCode = new byte[(int)size + 2];
            CrcHelper CrcHelper   = new CrcHelper(CrcAlgorithmType.Crc16Ccitt);
            ushort    CRC         = 0;

            RandomGenerator.GetBytes(NewCode);

            CRC = (ushort)CrcHelper.CalculateCrc(NewCode);

            Array.Copy(NewCode, 0, InstallCode, 0, NewCode.Length);

            InstallCode[InstallCode.Length - 2] = (byte)CRC;
            InstallCode[InstallCode.Length - 1] = (byte)(CRC >> 8);

            return(InstallCode);
        }