public static BigInteger CalculateDiffieHellmanSharedKey(string publicKey)
 {
     try
     {
         byte[] cbytes          = Converter.HexStringToBytes(publicKey);
         byte[] publicKeyBytes  = Rsa.Verify(cbytes);
         string publicKeyString = Encoding.Default.GetString(publicKeyBytes);
         return(DiffieHellman.CalculateSharedKey(new BigInteger(publicKeyString, 10)));
     }
     catch
     {
         return(0);
     }
 }
 public static BigInteger CalculateDiffieHellmanSharedKey(string publicKey)
 {
     try
     {
         var cbytes          = EncryptionUtilities.HexStringToBytes(publicKey);
         var publicKeyBytes  = Rsa.Verify(cbytes);
         var publicKeyString = Encoding.Default.GetString(publicKeyBytes);
         return(DiffieHellman.CalculateSharedKey(new BigInteger(publicKeyString, 10)));
     }
     catch
     {
         return(0);
     }
 }
        private static void TestHabboEncryption(bool consoleOutput, int dhBitLength, int rsaBitLength)
        {
            RSACrypto     serverRsa = new RSACrypto(RSACParameters.FromXmlFile(@"rsa.keys"));
            DiffieHellman serverDh  = DiffieHellman.CreateInstance(dhBitLength);

            string serverDhPrimeRsa = signDiffieHellmanKeys(serverDh.P, serverRsa);
            string serverDhGenRsa   = signDiffieHellmanKeys(serverDh.G, serverRsa);

            RSACrypto clientRsa = new RSACrypto(new RSACParameters(_modules, _exponent));

            BigInteger clientDhPrime = verifyDiffieHellmanKeys(serverDhPrimeRsa, clientRsa);
            BigInteger clientDhGen   = verifyDiffieHellmanKeys(serverDhGenRsa, clientRsa);

            DiffieHellman clientDh = new DiffieHellman(dhBitLength, clientDhPrime, clientDhGen);

            if (!clientDh.P.Equals(serverDh.P))
            {
                throw new Exception("HabboEncryption test FAILED, P keys are not equal!");
            }

            if (!clientDh.G.Equals(serverDh.G))
            {
                throw new Exception("HabboEncryption test FAILED, G keys are not equal!");
            }

            string serverDhPublicRsa = signDiffieHellmanKeys(serverDh.PublicKey, serverRsa);
            string clientDhPublicRsa = encryptDiffieHellmanKeys(clientDh.PublicKey, clientRsa);

            BigInteger serverDhClientPublic = decryptDiffieHellmanKeys(clientDhPublicRsa, serverRsa);
            BigInteger clientDhServerPublic = verifyDiffieHellmanKeys(serverDhPublicRsa, clientRsa);

            if (!clientDhServerPublic.Equals(serverDh.PublicKey))
            {
                throw new Exception("HabboEncryption test FAILED, server -> client public keys are not equal!");
            }

            if (!serverDhClientPublic.Equals(clientDh.PublicKey))
            {
                throw new Exception("HabboEncryption test FAILED, server <- client public keys are not equal!");
            }

            BigInteger serverDhShared = serverDh.CalculateSharedKey(serverDhClientPublic);
            BigInteger clientDhShared = clientDh.CalculateSharedKey(clientDhServerPublic);

            if (!serverDhShared.Equals(clientDhShared))
            {
                throw new Exception("HabboEncryption test FAILED, shared keys are not equal!");
            }
        }
Exemple #4
0
        public static BigInteger CalculateDiffieHellmanSharedKey(string publicKey)
        {
            try
            {
                byte[] bytes     = BigInteger.Parse('0' + publicKey, NumberStyles.HexNumber).ToByteArray();
                byte[] keyBytes  = Rsa.Verify(bytes);
                string keyString = Encoding.Default.GetString(keyBytes);

                return(DiffieHellman.CalculateSharedKey(BigInteger.Parse(keyString)));
            }
            catch
            {
                Writer.LogCriticalException("Sorry, the Encryption Handler stopped Inesperatelly. Please Restart Emulator.");
                return(0);
            }
        }
Exemple #5
0
        public static BigInteger CalculateDiffieHellmanSharedKey(string publicKey)
        {
            try
            {
                byte[] bytes     = BigInteger.Parse('0' + publicKey, NumberStyles.HexNumber).ToByteArray();
                byte[] keyBytes  = Rsa.Verify(bytes);
                string keyString = Encoding.Default.GetString(keyBytes);

                return(DiffieHellman.CalculateSharedKey(BigInteger.Parse(keyString)));
            }
            catch (Exception e)
            {
                YupiLogManager.LogCriticalException(e, "Encryption System Crashed.", "Yupi.Users");

                return(0);
            }
        }