Breaking News
Home / Java / Java Snippets / How to check if WEP Key is valid in Java?

How to check if WEP Key is valid in Java?

Snippet

  1.  private static final Pattern HEX_DIGITS = Pattern.compile("[0-9A-Fa-f]+");
  2.  
  3.   /**
  4.    * Check if wepKey is a valid hexadecimal string.
  5.    * @param wepKey the input to be checked
  6.    * @return true if the input string is indeed hex or empty.
  7.    * False if the input string is non-hex
  8.    * or null.
  9.    */
  10.   static boolean isHexWepKey(CharSequence wepKey) {
  11.     if (wepKey == null) {
  12.       return false;
  13.     }
  14.  
  15.     int length = wepKey.length();
  16.     // WEP-40, WEP-104, and some vendors using 256-bit WEP (WEP-232?)
  17.     return (length == 10 || length == 26 || length == 58) &&  
  18.             HEX_DIGITS.matcher(wepKey).matches();
  19.   }

<!>

[pb_builder]

Check Also

How to progamatically get the Java version?

Snippet The key here is to use the system property java.version and get minor and …

Advertisment ad adsense adlogger