本文整理汇总了Java中com.sun.org.apache.xerces.internal.impl.dv.util.Base64.encode方法的典型用法代码示例。如果您正苦于以下问题:Java Base64.encode方法的具体用法?Java Base64.encode怎么用?Java Base64.encode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.org.apache.xerces.internal.impl.dv.util.Base64
的用法示例。
在下文中一共展示了Base64.encode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saltedHash
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入方法依赖的package包/类
private static String saltedHash(String toHash, byte[] saltBytes) {
Random r = new Random();
if (saltBytes == null) {
saltBytes = new byte[SALT_SIZE];
r.nextBytes(saltBytes);
}
byte[] textBytes = toHash.getBytes();
byte[] textWithSaltBytes = new byte[textBytes.length + saltBytes.length];
System.arraycopy(textBytes, 0, textWithSaltBytes, 0, textBytes.length);
System.arraycopy(saltBytes, 0, textWithSaltBytes, textBytes.length, saltBytes.length);
byte[] hashBytes = Encryptor.hashBytes(textWithSaltBytes);
byte[] hashWithSaltBytes = new byte[hashBytes.length + saltBytes.length];
System.arraycopy(hashBytes, 0, hashWithSaltBytes, 0, hashBytes.length);
System.arraycopy(saltBytes, 0, hashWithSaltBytes, hashBytes.length, saltBytes.length);
return Base64.encode(hashWithSaltBytes);
}
示例2: main
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException{
String dirName="H:\\java\\ImageMatching-pHash(modified)\\src\\resources\\dataset";
ByteArrayOutputStream baos = new ByteArrayOutputStream(1000);
BufferedImage img = ImageIO.read(new File(dirName,"tempImage.jpg"));
ImageIO.write(img, "jpg", baos);
baos.flush();
String base64String = Base64.encode(baos.toByteArray());
baos.close();
byte[] bytearray = Base64.decode(base64String);
for(int i=0;i<bytearray.length;i++){
System.out.println(bytearray[i]);
}
BufferedImage imag = ImageIO.read(new ByteArrayInputStream(bytearray));
ImageIO.write(imag, "jpg", new File(dirName,"snap.jpg"));
}
示例3: process
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入方法依赖的package包/类
private BeanstreamResponse process(HttpUriRequest http,
ResponseHandler<BeanstreamResponse> responseHandler) throws IOException {
HttpClient httpclient;
if (customHttpClient != null)
httpclient = customHttpClient;
else
httpclient = HttpClients.createDefault();
// Remove newlines from base64 since they can bork the header.
// Some base64 encoders will append a newline to the end
String auth = Base64.encode((merchantId + ":" + apiPasscode).trim().getBytes());
http.addHeader("Content-Type", "application/json");
http.addHeader("Authorization", "Passcode " + auth);
BeanstreamResponse responseBody = httpclient.execute(http, responseHandler);
return responseBody;
}
示例4: subscribeTopic
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入方法依赖的package包/类
private String subscribeTopic(String timeout) {
String response = "";
try {
String requestURL = this.topicURL + "/events/" + this.topicname + "/mirrormakeragent/1?timeout=" + timeout
+ "&limit=1";
String authString = this.mechid + ":" + this.password;
String authStringEnc = Base64.encode(authString.getBytes());
URL url = new URL(requestURL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setDoOutput(true);
connection.setRequestProperty("Authorization", "Basic " + authStringEnc);
connection.setRequestProperty("Content-Type", "application/json");
InputStream content = (InputStream) connection.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(content));
String line;
while ((line = in.readLine()) != null) {
response = response + line;
}
Gson g = new Gson();
// get message as JSON String Array
String[] topicMessage = g.fromJson(response, String[].class);
if (topicMessage.length != 0) {
return topicMessage[0];
}
} catch (Exception e) {
return "ERROR:" + e.getMessage() + " Server Response is:" + response;
}
return null;
}
示例5: publishTopic
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入方法依赖的package包/类
private String publishTopic(String message) {
try {
String requestURL = this.topicURL + "/events/" + this.topicname;
String authString = this.mechid + ":" + this.password;
String authStringEnc = Base64.encode(authString.getBytes());
URL url = new URL(requestURL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("Authorization", "Basic " + authStringEnc);
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Content-Length", Integer.toString(message.length()));
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.write(message.getBytes());
InputStream content = (InputStream) connection.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(content));
String line;
String response = "";
while ((line = in.readLine()) != null) {
response = response + line;
}
return response;
} catch (Exception e) {
return "ERROR:" + e.getLocalizedMessage();
}
}
示例6: encrypt
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入方法依赖的package包/类
public static String encrypt(String s) throws Exception
{
SecretKeySpec key = new SecretKeySpec(keyBytes, ALGO);
cipher = Cipher.getInstance(ALGO);
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] encVal = cipher.doFinal(s.getBytes());
String encryptedValue = Base64.encode(encVal);
return encryptedValue;
//return encryptedValue.substring(0, encryptedValue.length()-1);
}
示例7: hash
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入方法依赖的package包/类
public static String hash(String toHash){
try {
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(toHash.getBytes("UTF-8"));
byte[] digest = md.digest();
return Base64.encode(digest);
} catch (NoSuchAlgorithmException | UnsupportedEncodingException ex) {
Logger.getLogger(Encryptor.class.getName()).log(Level.SEVERE, null, ex);
}
throw new RuntimeException("Failed to hash String");
}
示例8: imageToByteArray
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入方法依赖的package包/类
public static byte[] imageToByteArray(String imagePath)throws IOException{
ByteArrayOutputStream baos = new ByteArrayOutputStream(1000);
BufferedImage img = ImageIO.read(new File(imagePath));
ImageIO.write(img, "jpg", baos);
baos.flush();
String base64String = Base64.encode(baos.toByteArray());
baos.close();
byte[] bytearray = Base64.decode(base64String);
return bytearray;
}
示例9: loadAndEncode
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入方法依赖的package包/类
public static String loadAndEncode(File imgFile, int maxWidth, int maxHeight) {
try {
final BufferedImage original = ImageIO.read(imgFile);
final BufferedImage resized = new BufferedImage(maxWidth, maxHeight, BufferedImage.TYPE_INT_ARGB);
final Graphics2D g = resized.createGraphics();
final Image temp;
if (original.getWidth() > original.getHeight()) {
temp = original.getScaledInstance(-1, maxHeight, Image.SCALE_SMOOTH);
} else {
temp = original.getScaledInstance(maxWidth, -1, Image.SCALE_SMOOTH);
}
g.drawImage(temp,
(int) (maxWidth * 0.5 - temp.getWidth(null) * 0.5),
(int) (maxHeight * 0.5 - temp.getHeight(null) * 0.5),
null
);
byte[] bytes;
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
ImageIO.write(resized, "jpg", baos);
baos.flush();
bytes = baos.toByteArray();
}
g.dispose();
return Base64.encode(bytes);
} catch (IOException ex) {
Logger.getLogger(JSONImage.class.getName())
.log(Level.SEVERE, "Could not read image '" + imgFile.getName() + "'.", ex);
return null;
}
}
示例10: encrypt
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入方法依赖的package包/类
public String encrypt(String str, String hmpServerId, String vistaSystemId) throws BadPaddingException, IllegalBlockSizeException, NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException {
if(!cinit) {
cinit(hmpServerId,vistaSystemId);
}
String encrypted = new String(Base64.encode(encipher.doFinal(str.getBytes())));
return encrypted;
}
示例11: signToBase64
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入方法依赖的package包/类
/**
* A handy version of {@link #sign(HttpMethod, java.net.URI, LinkedListMultimap,
* String, SignAlgorithm)}, generates base64 encoded sign result.
*/
public static String signToBase64(HttpMethod httpMethod, URI uri,
LinkedListMultimap<String, String> httpHeaders, String secretAccessKeyId,
SignAlgorithm algorithm) throws NoSuchAlgorithmException,
InvalidKeyException {
return Base64.encode(sign(httpMethod, uri, httpHeaders, secretAccessKeyId,
algorithm));
}
示例12: toString
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入方法依赖的package包/类
public synchronized String toString() {
if (canonical == null) {
canonical = Base64.encode(data);
}
return canonical;
}
示例13: getBase64EncodedStringFromImage
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入方法依赖的package包/类
/**
* Encode a BufferedImage in a Base64 string
* @param img Image to encode
* @return Encoded Base64 image string
*/
protected String getBase64EncodedStringFromImage(BufferedImage img) throws IOException {
byte[] imgData = getByteArrayFromImage(img);
String base64bytes = Base64.encode(imgData);
return "data:image/png;base64," + base64bytes;
}
示例14: commence
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入方法依赖的package包/类
@Override
public void commence(
HttpServletRequest request,
HttpServletResponse response,
org.springframework.security.core.AuthenticationException authException)
throws IOException, ServletException {
//super.commence(request, response, authException);
HttpServletResponse httpResponse = (HttpServletResponse) response;
// compute a nonce (do not use remote IP address due to proxy farms)
// format of nonce is:
// base64(expirationTime + ":" + md5Hex(expirationTime + ":" + key))
long expiryTime = System.currentTimeMillis() + (getNonceValiditySeconds() * 1000);
String signatureValue = DigestUtils.md5Hex(expiryTime + ":" + getKey());
String nonceValue = expiryTime + ":" + signatureValue;
String nonceValueBase64 = new String(Base64.encode(nonceValue.getBytes()));
// qop is quality of protection, as defined by RFC 2617.
// we do not use opaque due to IE violation of RFC 2617 in not
// representing opaque on subsequent requests in same session.
String authenticateHeader = "Digest realm=\"" + getRealmName() + "\", " + "qop=\"auth\", nonce=\""
+ nonceValueBase64 + "\"";
if (authException instanceof NonceExpiredException) {
authenticateHeader = authenticateHeader + ", stale=\"true\"";
}
httpResponse.addHeader("WWW-Authenticate", authenticateHeader);
//old HTML response
//httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, authException.getMessage());
//custom response for digest authentication
httpResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
httpResponse.setContentType("application/json");
httpResponse.setCharacterEncoding("UTF-8");
httpResponse.getWriter().write("{\"error\":\"Authentication failed, wrong credentials for HTTP-Digest authentication\"}");
}
示例15: setContent
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入方法依赖的package包/类
public void setContent(byte[] content) throws IOException {
checkContentLength(content == null ? 0 : content.length);
this.rawContent = content;
this.content = Base64.encode(content);
}