/java/com/l2jserver/gameserver/network/gameserverpackets/BlowFishKey.java

https://github.com/ichiro101/l2adena-l2j-core · Java · 65 lines · 34 code · 6 blank · 25 comment · 0 complexity · 2353918f85837406fa43e1baf90234c8 MD5 · raw file

  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.network.gameserverpackets;
  16. import java.io.IOException;
  17. import java.security.GeneralSecurityException;
  18. import java.security.interfaces.RSAPublicKey;
  19. import java.util.logging.Level;
  20. import java.util.logging.Logger;
  21. import javax.crypto.Cipher;
  22. import com.l2jserver.util.network.BaseSendablePacket;
  23. /**
  24. * @author -Wooden-
  25. *
  26. */
  27. public class BlowFishKey extends BaseSendablePacket
  28. {
  29. private static Logger _log = Logger.getLogger(BlowFishKey.class.getName());
  30. /**
  31. * @param blowfishKey
  32. * @param publicKey
  33. */
  34. public BlowFishKey(byte[] blowfishKey, RSAPublicKey publicKey)
  35. {
  36. writeC(0x00);
  37. byte[] encrypted =null;
  38. try
  39. {
  40. Cipher rsaCipher = Cipher.getInstance("RSA/ECB/nopadding");
  41. rsaCipher.init(Cipher.ENCRYPT_MODE, publicKey);
  42. encrypted = rsaCipher.doFinal(blowfishKey);
  43. }
  44. catch(GeneralSecurityException e)
  45. {
  46. _log.log(Level.SEVERE, "Error While encrypting blowfish key for transmision (Crypt error): " + e.getMessage(), e);
  47. }
  48. writeD(encrypted.length);
  49. writeB(encrypted);
  50. }
  51. /* (non-Javadoc)
  52. * @see com.l2jserver.gameserver.gameserverpackets.GameServerBasePacket#getContent()
  53. */
  54. @Override
  55. public byte[] getContent() throws IOException
  56. {
  57. return getBytes();
  58. }
  59. }