BlowFishKey.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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.Logger;
  20. import javax.crypto.Cipher;
  21. /**
  22. * @author -Wooden-
  23. *
  24. */
  25. public class BlowFishKey extends GameServerBasePacket
  26. {
  27. private static Logger _log = Logger.getLogger(BlowFishKey.class.getName());
  28. /**
  29. * @param blowfishKey
  30. * @param publicKey
  31. */
  32. public BlowFishKey(byte[] blowfishKey, RSAPublicKey publicKey)
  33. {
  34. writeC(0x00);
  35. byte[] encrypted =null;
  36. try
  37. {
  38. Cipher rsaCipher = Cipher.getInstance("RSA/ECB/nopadding");
  39. rsaCipher.init(Cipher.ENCRYPT_MODE, publicKey);
  40. encrypted = rsaCipher.doFinal(blowfishKey);
  41. }
  42. catch(GeneralSecurityException e)
  43. {
  44. _log.severe("Error While encrypting blowfish key for transmision (Crypt error)");
  45. e.printStackTrace();
  46. }
  47. writeD(encrypted.length);
  48. writeB(encrypted);
  49. }
  50. /* (non-Javadoc)
  51. * @see com.l2jserver.gameserver.gameserverpackets.GameServerBasePacket#getContent()
  52. */
  53. @Override
  54. public byte[] getContent() throws IOException
  55. {
  56. return getBytes();
  57. }
  58. }