You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VncAuth.java 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
  16. * USA.
  17. */
  18. package com.tigervnc.rfb;
  19. public class VncAuth {
  20. public static final int ok = 0;
  21. public static final int failed = 1;
  22. public static final int tooMany = 2; // deprecated
  23. public static final int challengeSize = 16;
  24. public static void encryptChallenge(byte[] challenge, String passwd) {
  25. byte[] key = new byte[8];
  26. for (int i = 0; i < 8 && i < passwd.length(); i++) {
  27. key[i] = (byte)passwd.charAt(i);
  28. }
  29. DesCipher des = new DesCipher(key);
  30. for (int j = 0; j < challengeSize; j += 8)
  31. des.encrypt(challenge,j,challenge,j);
  32. }
  33. void obfuscatePasswd(String passwd, byte[] obfuscated) {
  34. for (int i = 0; i < 8; i++) {
  35. if (i < passwd.length())
  36. obfuscated[i] = (byte)passwd.charAt(i);
  37. else
  38. obfuscated[i] = 0;
  39. }
  40. DesCipher des = new DesCipher(obfuscationKey);
  41. des.encrypt(obfuscated,0,obfuscated,0);
  42. }
  43. public static String unobfuscatePasswd(byte[] obfuscated) {
  44. DesCipher des = new DesCipher(obfuscationKey);
  45. des.decrypt(obfuscated,0,obfuscated,0);
  46. int len;
  47. for (len = 0; len < 8; len++) {
  48. if (obfuscated[len] == 0) break;
  49. }
  50. char[] plain = new char[len];
  51. for (int i = 0; i < len; i++) {
  52. plain[i] = (char)obfuscated[i];
  53. }
  54. return new String(plain);
  55. }
  56. static byte[] obfuscationKey = {23,82,107,6,35,78,88,7};
  57. }