2
0

BlowFishKey.java 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. import com.l2jserver.util.network.BaseSendablePacket;
  22. /**
  23. * @author -Wooden-
  24. *
  25. */
  26. public class BlowFishKey extends BaseSendablePacket
  27. {
  28. private static Logger _log = Logger.getLogger(BlowFishKey.class.getName());
  29. /**
  30. * @param blowfishKey
  31. * @param publicKey
  32. */
  33. public BlowFishKey(byte[] blowfishKey, RSAPublicKey publicKey)
  34. {
  35. writeC(0x00);
  36. byte[] encrypted =null;
  37. try
  38. {
  39. Cipher rsaCipher = Cipher.getInstance("RSA/ECB/nopadding");
  40. rsaCipher.init(Cipher.ENCRYPT_MODE, publicKey);
  41. encrypted = rsaCipher.doFinal(blowfishKey);
  42. }
  43. catch(GeneralSecurityException e)
  44. {
  45. _log.severe("Error While encrypting blowfish key for transmision (Crypt error)");
  46. e.printStackTrace();
  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. }