我正在尝试改变这个专有的
private String getSecWebSocketAccept(String secKey)
throws UnsupportedEncodingException, NoSuchAlgorithmException {
String guid = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
secKey += guid;
MessageDigest md = MessageDigest.getInstance("SHA-1");
md.update(secKey.getBytes("ISO-8859-1"), 0, secKey.length());
byte[] shalHash = md.digest();
BASE64Encoder encoder = new BASE64Encoder();
return encoder.encode(shalHash);
}
编码为 apache 版本
org.apache.commons.codec.binary.Base64
但是当我尝试时它根本行不通
private String getSecWebSocketAccept(String secKey)
throws UnsupportedEncodingException, NoSuchAlgorithmException {
String guid = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
secKey += guid;
MessageDigest md = MessageDigest.getInstance("SHA-1");
md.update(secKey.getBytes("ISO-8859-1"), 0, secKey.length());
byte[] shalHash = md.digest();
org.apache.commons.codec.binary.Base64.encodeBase64 encoder = new org.apache.commons.codec.binary.Base64.encodeBase64();
return encoder.encode(shalHash);
}
这是我得到的错误
C:\xampp\htdocs\html>javac SimpleServer.java
SimpleServer.java:87: error: cannot find symbol
org.apache.commons.codec.binary.Base64.encodeBase64 encoder = ne
w org.apache.commons.codec.binary.Base64.encodeBase64();
^
symbol: class encodeBase64
location: class Base64
SimpleServer.java:87: error: cannot find symbol
org.apache.commons.codec.binary.Base64.encodeBase64 encoder = ne
w org.apache.commons.codec.binary.Base64.encodeBase64();
^
symbol: class encodeBase64
location: class Base64
2 errors