Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private KeyState CheckKey(string key) { // key length: 32 chars
- byte[] buffer = new byte[key.Length / 2];
- int num = 0;
- for (int i = 0; i < key.Length; i += 2) {
- try {
- buffer[num] = Convert.ToByte(key.Substring(i, 2), 16);
- } catch {
- return KeyState.InvalidKey;
- }
- num++;
- }
- MemoryStream memoryStream = new MemoryStream();
- CryptoStream cryptoStream = null;
- try {
- cryptoStream = new CryptoStream(memoryStream,
- new TripleDESCryptoServiceProvider().CreateDecryptor(SecretKey, Iv), CryptoStreamMode.Write);
- } catch {
- cryptoStream = null;
- return KeyState.Unknown;
- }
- byte[] arr = null;
- if (cryptoStream != null) {
- try {
- cryptoStream.Write(buffer, 0, buffer.Length);
- cryptoStream.FlushFinalBlock(); // <---- System.Security.Cryptography.CryptographicException: Bad Data.
- memoryStream.Position = 0L;
- arr = memoryStream.ToArray();
- cryptoStream.Close();
- memoryStream.Close();
- } catch {
- return KeyState.InvalidKey;
- }
- }
- if (arr[0] != _licenseVersion[0] || arr[1] != _licenseVersion[1] || arr[2] != _licenseVersion[2] ||
- arr[3] != _licenseVersion[3]) {
- return KeyState.WrongProductKey;
- }
- if (arr[6] != byte_0[arr[4], arr[5]] && arr[9] != byte_0[arr[7], arr[8]]) {
- return KeyState.WrongKey;
- }
- return KeyState.OK;
- }
Advertisement
Add Comment
Please, Sign In to add comment