    001    package net.minecraft.network.packet;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import java.io.DataInputStream;
    006    import java.io.DataOutputStream;
    007    import java.io.IOException;
    008    import java.security.PrivateKey;
    009    import java.security.PublicKey;
    010    import javax.crypto.SecretKey;
    011    import net.minecraft.util.CryptManager;
    012
    013    public class Packet252SharedKey extends Packet
    014    {
    015        private byte[] sharedSecret = new byte[0];
    016        private byte[] verifyToken = new byte[0];
    017        private SecretKey field_73306_c;
    018
    019        public Packet252SharedKey() {}
    020
    021        @SideOnly(Side.CLIENT)
    022        public Packet252SharedKey(SecretKey par1SecretKey, PublicKey par2PublicKey, byte[] par3ArrayOfByte)
    023        {
    024            this.field_73306_c = par1SecretKey;
    025            this.sharedSecret = CryptManager.func_75894_a(par2PublicKey, par1SecretKey.getEncoded());
    026            this.verifyToken = CryptManager.func_75894_a(par2PublicKey, par3ArrayOfByte);
    027        }
    028
    029        /**
    030         * Abstract. Reads the raw packet data from the data stream.
    031         */
    032        public void readPacketData(DataInputStream par1DataInputStream) throws IOException
    033        {
    034            this.sharedSecret = readBytesFromStream(par1DataInputStream);
    035            this.verifyToken = readBytesFromStream(par1DataInputStream);
    036        }
    037
    038        /**
    039         * Abstract. Writes the raw packet data to the data stream.
    040         */
    041        public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException
    042        {
    043            writeByteArray(par1DataOutputStream, this.sharedSecret);
    044            writeByteArray(par1DataOutputStream, this.verifyToken);
    045        }
    046
    047        /**
    048         * Passes this Packet on to the NetHandler for processing.
    049         */
    050        public void processPacket(NetHandler par1NetHandler)
    051        {
    052            par1NetHandler.handleSharedKey(this);
    053        }
    054
    055        /**
    056         * Abstract. Return the size of the packet (not counting the header).
    057         */
    058        public int getPacketSize()
    059        {
    060            return 2 + this.sharedSecret.length + 2 + this.verifyToken.length;
    061        }
    062
    063        public SecretKey func_73303_a(PrivateKey par1PrivateKey)
    064        {
    065            return par1PrivateKey == null ? this.field_73306_c : (this.field_73306_c = CryptManager.func_75887_a(par1PrivateKey, this.sharedSecret));
    066        }
    067
    068        public SecretKey func_73304_d()
    069        {
    070            return this.func_73303_a((PrivateKey)null);
    071        }
    072
    073        public byte[] func_73302_b(PrivateKey par1PrivateKey)
    074        {
    075            return par1PrivateKey == null ? this.verifyToken : CryptManager.func_75889_b(par1PrivateKey, this.verifyToken);
    076        }
    077    }