当前位置: 首页>>代码示例>>C#>>正文


C# javax.getEncoded方法代码示例

本文整理汇总了C#中javax.getEncoded方法的典型用法代码示例。如果您正苦于以下问题:C# javax.getEncoded方法的具体用法?C# javax.getEncoded怎么用?C# javax.getEncoded使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax的用法示例。


在下文中一共展示了javax.getEncoded方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: StartEncryption

        public bool StartEncryption(string username, string sessionID, byte[] token, string serverIDhash, java.security.PublicKey serverKey, javax.crypto.SecretKey secretKey)
        {
            Console.ForegroundColor = ConsoleColor.DarkGray;
            ConsoleIO.WriteLine("Crypto keys & hash generated.");
            Console.ForegroundColor = ConsoleColor.Gray;

            if (serverIDhash != "-")
            {
                Console.WriteLine("Checking Session...");
                if (!SessionCheck(username, sessionID, new java.math.BigInteger(Crypto.getServerHash(serverIDhash, serverKey, secretKey)).toString(16)))
                {
                    return false;
                }
            }

            //Encrypt the data
            byte[] key_enc = Crypto.Encrypt(serverKey, secretKey.getEncoded());
            byte[] token_enc = Crypto.Encrypt(serverKey, token);
            byte[] keylen = BitConverter.GetBytes((short)key_enc.Length);
            byte[] tokenlen = BitConverter.GetBytes((short)token_enc.Length);

            Array.Reverse(keylen);
            Array.Reverse(tokenlen);

            //Building the packet
            byte[] data = new byte[5 + (short)key_enc.Length + (short)token_enc.Length];
            data[0] = 0xFC;
            keylen.CopyTo(data, 1);
            key_enc.CopyTo(data, 3);
            tokenlen.CopyTo(data, 3 + (short)key_enc.Length);
            token_enc.CopyTo(data, 5 + (short)key_enc.Length);

            //Send it back
            Send(data);

            //Getting the next packet
            byte[] pid = new byte[1];
            Receive(pid, 0, 1, SocketFlags.None);
            if (pid[0] == 0xFC)
            {
                readData(4);
                setEncryptedClient(Crypto.SwitchToAesMode(c.GetStream(), secretKey));
                return true;
            }
            else return false;
        }
开发者ID:justcool393,项目名称:Minecraft-Console-Client,代码行数:46,代码来源:MinecraftCom.cs

示例2: StartEncryption

        public bool StartEncryption(string uuid, string sessionID, byte[] token, string serverIDhash, java.security.PublicKey serverKey, javax.crypto.SecretKey secretKey)
        {
            Console.ForegroundColor = ConsoleColor.DarkGray;
            ConsoleIO.WriteLine("Crypto keys & hash generated.");
            Console.ForegroundColor = ConsoleColor.Gray;

            if (serverIDhash != "-")
            {
                Console.WriteLine("Checking Session...");
                if (!SessionCheck(uuid, sessionID, new java.math.BigInteger(Crypto.getServerHash(serverIDhash, serverKey, secretKey)).toString(16)))
                {
                    return false;
                }
            }

            //Encrypt the data
            byte[] key_enc = Crypto.Encrypt(serverKey, secretKey.getEncoded());
            byte[] token_enc = Crypto.Encrypt(serverKey, token);
            byte[] key_len = BitConverter.GetBytes((short)key_enc.Length); Array.Reverse(key_len);
            byte[] token_len = BitConverter.GetBytes((short)token_enc.Length); Array.Reverse(token_len);

            //Encryption Response packet
            byte[] packet_id = getVarInt(0x01);
            byte[] encryption_response = concatBytes(packet_id, key_len, key_enc, token_len, token_enc);
            byte[] encryption_response_tosend = concatBytes(getVarInt(encryption_response.Length), encryption_response);
            Send(encryption_response_tosend);

            //Start client-side encryption
            setEncryptedClient(Crypto.SwitchToAesMode(c.GetStream(), secretKey));

            //Get the next packet
            readNextVarInt(); //Skip Packet size (not needed)
            return (readNextVarInt() == 0x02); //Packet ID. 0x02 = Login Success
        }
开发者ID:johndpalm,项目名称:Minecraft-Console-Client,代码行数:34,代码来源:MinecraftCom.cs


注:本文中的javax.getEncoded方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。