jodd.util.Base64.encodeToString()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(311)

本文整理了Java中jodd.util.Base64.encodeToString()方法的一些代码示例,展示了Base64.encodeToString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Base64.encodeToString()方法的具体详情如下:
包路径:jodd.util.Base64
类名称:Base64
方法名:encodeToString

Base64.encodeToString介绍

[英]Encodes a raw byte array into a BASE64 String.
[中]将原始字节数组编码为BASE64String

代码示例

代码示例来源:origin: oblac/jodd

/**
 * Symmetrically encrypts the string.
 */
public String encrypt(final String str) {
  try {
    byte[] utf8 = StringUtil.getBytes(str);		// encode the string into bytes using utf-8
    byte[] enc = ecipher.doFinal(utf8); 	// encrypt
    return Base64.encodeToString(enc);		// encode bytes to base64 to get a string
  } catch (Throwable ignore) {
    return null;
  }
}

代码示例来源:origin: oblac/jodd

/**
 * Enables basic authentication by adding required header.
 */
public HttpRequest basicAuthentication(final String username, final String password) {
  if (username != null && password != null) {
    String data = username.concat(StringPool.COLON).concat(password);
    String base64 = Base64.encodeToString(data);
    headerOverwrite(HEADER_AUTHORIZATION, "Basic " + base64);
  }
  return this;
}

代码示例来源:origin: oblac/jodd

/**
 * Encodes the {@link SimTok} to JSON string.
 */
public String encode(final SimTok simTok) {
  final String json = JsonSerializer.create().deep(true).serialize(simTok);
  final String p1 = Base64.encodeToString("JoddSimTok" + SALT_ROUNDS);
  final String p2 = Base64.encodeToString(json);
  final String salt = BCrypt.gensalt(SALT_ROUNDS);
  final String p3 = BCrypt.hashpw(p1 + "." + p2 + "." + SECRET, salt);
  return p1 + "." + p2 + "." + p3;
}

代码示例来源:origin: oblac/jodd

@Test
void testEncoding() {
  assertEquals(enc, Base64.encodeToString(text));
  assertEquals("TQ==", Base64.encodeToString("M"));
  assertEquals("TWE=", Base64.encodeToString("Ma"));
  assertEquals("TWFu", Base64.encodeToString("Man"));
}

代码示例来源:origin: oblac/jodd

proxyLine =
    "Proxy-Authorization: Basic " +
    Base64.encodeToString((username + ":" + password)) + "\r\n";

代码示例来源:origin: oblac/jodd

@Override
  public boolean serialize(final JsonContext jsonContext, final File file) {
    switch (serializationType) {
      case PATH:
        jsonContext.writeString(file.getAbsolutePath());
        break;
      case NAME:
        jsonContext.writeString(file.getName());
        break;
      case CONTENT: {
          byte[] bytes;

          try {
            bytes = FileUtil.readBytes(file);
          }
          catch (IOException e) {
            throw new JsonException("Unable to read files content", e);
          }

          String encoded = Base64.encodeToString(bytes);

          jsonContext.writeString(encoded);
        }
        break;
      default:
        throw new JsonException("Invalid type");
    }
    return true;
  }
}

代码示例来源:origin: oblac/jodd

@Test
void testUTF8() {
  String utf8string = "Здоровая";
  String encoded = Base64.encodeToString(utf8string);
  String decoded = Base64.decodeToString(encoded);
  assertEquals(utf8string, decoded);
  for (int i = 0; i < 10; i++) {
    utf8string += utf8string;
  }
  assertTrue(utf8string.length() > 76);
  byte[] encodedBytes = Base64.encodeToByte(utf8string, true);
  decoded = Base64.decodeToString(encodedBytes);
  assertEquals(utf8string, decoded);
  encoded = Base64.encodeToString(utf8string, true);
  decoded = Base64.decodeToString(encoded);
  assertEquals(utf8string, decoded);
}

代码示例来源:origin: org.jodd/jodd-http

/**
 * Enables basic authentication by adding required header.
 */
public HttpRequest basicAuthentication(final String username, final String password) {
  if (username != null && password != null) {
    String data = username.concat(StringPool.COLON).concat(password);
    String base64 = Base64.encodeToString(data);
    headerOverwrite(HEADER_AUTHORIZATION, "Basic " + base64);
  }
  return this;
}

代码示例来源:origin: org.jodd/jodd-core

/**
 * Symmetrically encrypts the string.
 */
public String encrypt(final String str) {
  try {
    byte[] utf8 = StringUtil.getBytes(str);		// encode the string into bytes using utf-8
    byte[] enc = ecipher.doFinal(utf8); 	// encrypt
    return Base64.encodeToString(enc);		// encode bytes to base64 to get a string
  } catch (Throwable ignore) {
    return null;
  }
}

代码示例来源:origin: org.jodd/jodd-joy

/**
 * Encodes the {@link SimTok} to JSON string.
 */
public String encode(final SimTok simTok) {
  final String json = JsonSerializer.create().deep(true).serialize(simTok);
  final String p1 = Base64.encodeToString("JoddSimTok" + SALT_ROUNDS);
  final String p2 = Base64.encodeToString(json);
  final String salt = BCrypt.gensalt(SALT_ROUNDS);
  final String p3 = BCrypt.hashpw(p1 + "." + p2 + "." + SECRET, salt);
  return p1 + "." + p2 + "." + p3;
}

代码示例来源:origin: com.github.binarywang/weixin-java-pay

@Override
public byte[] postForBytes(String url, String requestStr, boolean useKey) throws WxPayException {
 try {
  HttpRequest request = this.buildHttpRequest(url, requestStr, useKey);
  byte[] responseBytes = request.send().bodyBytes();
  final String responseString = Base64.encodeToString(responseBytes);
  this.log.info("\n【请求地址】:{}\n【请求数据】:{}\n【响应数据(Base64编码后)】:{}", url, requestStr, responseString);
  if (this.getConfig().isIfSaveApiData()) {
   wxApiData.set(new WxPayApiData(url, requestStr, responseString, null));
  }
  return responseBytes;
 } catch (Exception e) {
  this.log.error("\n【请求地址】:{}\n【请求数据】:{}\n【异常信息】:{}", url, requestStr, e.getMessage());
  wxApiData.set(new WxPayApiData(url, requestStr, null, e.getMessage()));
  throw new WxPayException(e.getMessage(), e);
 }
}

代码示例来源:origin: com.github.binarywang/weixin-java-pay

@Override
public byte[] postForBytes(String url, String requestStr, boolean useKey) throws WxPayException {
 try {
  HttpClientBuilder httpClientBuilder = createHttpClientBuilder(useKey);
  HttpPost httpPost = this.createHttpPost(url, requestStr);
  try (CloseableHttpClient httpClient = httpClientBuilder.build()) {
   try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
    final byte[] bytes = EntityUtils.toByteArray(response.getEntity());
    final String responseData = Base64.encodeToString(bytes);
    this.log.info("\n【请求地址】:{}\n【请求数据】:{}\n【响应数据(Base64编码后)】:{}", url, requestStr, responseData);
    wxApiData.set(new WxPayApiData(url, requestStr, responseData, null));
    return bytes;
   }
  } finally {
   httpPost.releaseConnection();
  }
 } catch (Exception e) {
  this.log.error("\n【请求地址】:{}\n【请求数据】:{}\n【异常信息】:{}", url, requestStr, e.getMessage());
  wxApiData.set(new WxPayApiData(url, requestStr, null, e.getMessage()));
  throw new WxPayException(e.getMessage(), e);
 }
}

代码示例来源:origin: binarywang/WxJava

@Override
public byte[] postForBytes(String url, String requestStr, boolean useKey) throws WxPayException {
 try {
  HttpClientBuilder httpClientBuilder = createHttpClientBuilder(useKey);
  HttpPost httpPost = this.createHttpPost(url, requestStr);
  try (CloseableHttpClient httpClient = httpClientBuilder.build()) {
   try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
    final byte[] bytes = EntityUtils.toByteArray(response.getEntity());
    final String responseData = Base64.encodeToString(bytes);
    this.log.info("\n【请求地址】:{}\n【请求数据】:{}\n【响应数据(Base64编码后)】:{}", url, requestStr, responseData);
    wxApiData.set(new WxPayApiData(url, requestStr, responseData, null));
    return bytes;
   }
  } finally {
   httpPost.releaseConnection();
  }
 } catch (Exception e) {
  this.log.error("\n【请求地址】:{}\n【请求数据】:{}\n【异常信息】:{}", url, requestStr, e.getMessage());
  wxApiData.set(new WxPayApiData(url, requestStr, null, e.getMessage()));
  throw new WxPayException(e.getMessage(), e);
 }
}

代码示例来源:origin: binarywang/WxJava

@Override
public byte[] postForBytes(String url, String requestStr, boolean useKey) throws WxPayException {
 try {
  HttpRequest request = this.buildHttpRequest(url, requestStr, useKey);
  byte[] responseBytes = request.send().bodyBytes();
  final String responseString = Base64.encodeToString(responseBytes);
  this.log.info("\n【请求地址】:{}\n【请求数据】:{}\n【响应数据(Base64编码后)】:{}", url, requestStr, responseString);
  if (this.getConfig().isIfSaveApiData()) {
   wxApiData.set(new WxPayApiData(url, requestStr, responseString, null));
  }
  return responseBytes;
 } catch (Exception e) {
  this.log.error("\n【请求地址】:{}\n【请求数据】:{}\n【异常信息】:{}", url, requestStr, e.getMessage());
  wxApiData.set(new WxPayApiData(url, requestStr, null, e.getMessage()));
  throw new WxPayException(e.getMessage(), e);
 }
}

代码示例来源:origin: org.jodd/jodd-http

proxyLine =
    "Proxy-Authorization: Basic " +
    Base64.encodeToString((username + ":" + password)) + "\r\n";

相关文章

微信公众号

最新文章

更多