the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 63 lines 1.4 kB view raw
1#pragma once 2 3#include "Packet.h" 4 5class SharedKeyPacket : public Packet 6{ 7#if 0 8 private byte[] keybytes = new byte[]{}; 9 private byte[] nonce = new byte[]{}; 10 11 private SecretKey secretKey; 12 13 public SharedKeyPacket() { 14 // Needed 15 } 16 17 public SharedKeyPacket(final SecretKey secretKey, final PublicKey publicKey, final byte[] nonce) { 18 this.secretKey = secretKey; 19 this.keybytes = Crypt.encryptUsingKey(publicKey, secretKey.getEncoded()); 20 this.nonce = Crypt.encryptUsingKey(publicKey, nonce); 21 } 22 23 @Override 24 public void read(DataInputStream dis) throws IOException { 25 keybytes = readBytes(dis); 26 nonce = readBytes(dis); 27 } 28 29 @Override 30 public void write(DataOutputStream dos) throws IOException { 31 writeBytes(dos, keybytes); 32 writeBytes(dos, nonce); 33 } 34 35 @Override 36 public void handle(PacketListener listener) { 37 listener.handleSharedKey(this); 38 } 39 40 @Override 41 public int getEstimatedSize() { 42 return 2 + keybytes.length + 2 + nonce.length; 43 } 44 45 public SecretKey getSecretKey(PrivateKey privateKey) { 46 if (privateKey == null) { 47 return secretKey; 48 } 49 return secretKey = Crypt.decryptByteToSecretKey(privateKey, keybytes); 50 } 51 52 public SecretKey getSecretKey() { 53 return getSecretKey(null); 54 } 55 56 public byte[] getNonce(PrivateKey privateKey) { 57 if (privateKey == null) { 58 return nonce; 59 } 60 return Crypt.decryptUsingKey(privateKey, nonce); 61 } 62#endif 63};