org.apache.commons.net.util.Base64.encodeBase64String()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.2k)|赞(0)|评价(0)|浏览(209)

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

Base64.encodeBase64String介绍

[英]Encodes binary data using the base64 algorithm into 76 character blocks separated by CRLF.

For a non-chunking version, see #encodeBase64StringUnChunked(byte[]).
[中]使用base64算法将二进制数据编码为由CRLF分隔的76个字符块。
有关非分块版本,请参阅#encodeBase64StringUnChunked(字节[])。

代码示例

代码示例来源:origin: deeplearning4j/nd4j

@Override
  public void process(Exchange exchange) throws Exception {
    final INDArray arr = (INDArray) exchange.getIn().getBody();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bos);
    Nd4j.write(arr, dos);
    byte[] bytes = bos.toByteArray();
    String base64 = Base64.encodeBase64String(bytes);
    exchange.getIn().setBody(base64, String.class);
    String id = UUID.randomUUID().toString();
    exchange.getIn().setHeader(KafkaConstants.KEY, id);
    exchange.getIn().setHeader(KafkaConstants.PARTITION_KEY, id);
  }
}).to(kafkaUri);

代码示例来源:origin: deeplearning4j/nd4j

/**
 * Returns an ndarray
 * as base 64
 * @param arr the array to write
 * @return the base 64 representation of the binary
 * ndarray
 * @throws IOException
 */
public static String base64String(INDArray arr) throws IOException {
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  DataOutputStream dos = new DataOutputStream(bos);
  Nd4j.write(arr, dos);
  String base64 = Base64.encodeBase64String(bos.toByteArray());
  return base64;
}

代码示例来源:origin: deeplearning4j/nd4j

/**
 * Returns a tab delimited base 64
 * representation of the given arrays
 * @param arrays the arrays
 * @return
 * @throws IOException
 */
public static String arraysToBase64(INDArray[] arrays) throws IOException {
  StringBuilder sb = new StringBuilder();
  //tab separate the outputs for de serialization
  for (INDArray outputArr : arrays) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bos);
    Nd4j.write(outputArr, dos);
    String base64 = Base64.encodeBase64String(bos.toByteArray());
    sb.append(base64);
    sb.append("\t");
  }
  return sb.toString();
}

代码示例来源:origin: mustfun/mybatis-plus

public static String[] genKeyPair(int keySize)
    throws NoSuchAlgorithmException, NoSuchProviderException {
  byte[][] keyPairBytes = genKeyPairBytes(keySize);
  String[] keyPairs = new String[2];
  keyPairs[0] = Base64.encodeBase64String(keyPairBytes[0]);
  keyPairs[1] = Base64.encodeBase64String(keyPairBytes[1]);
  return keyPairs;
}

代码示例来源:origin: com.centit.support/centit-utils

public static String keyPairToJson(KeyPair keyPair) {
  Map<String,String> keyJson = new HashMap<>();
  keyJson.put("private", Base64.encodeBase64String(keyPair.getPrivate().getEncoded()));
  keyJson.put("public", Base64.encodeBase64String(keyPair.getPublic().getEncoded()));
  return JSON.toJSONString(keyJson);
}

代码示例来源:origin: org.nd4j/nd4j-base64

/**
 * Returns an ndarray
 * as base 64
 * @param arr the array to write
 * @return the base 64 representation of the binary
 * ndarray
 * @throws IOException
 */
public static String base64String(INDArray arr) throws IOException {
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  DataOutputStream dos = new DataOutputStream(bos);
  Nd4j.write(arr, dos);
  String base64 = Base64.encodeBase64String(bos.toByteArray());
  return base64;
}

代码示例来源:origin: hopshadoop/hopsworks

/**
 *
 * @param key
 * @param plaintext
 * @return
 * @throws Exception
 */
public static String encrypt(String key, String plaintext, String masterEncryptionPassword)
  throws Exception {
 
 Key aesKey = generateKey(key, masterEncryptionPassword);
 Cipher cipher = Cipher.getInstance("AES");
 cipher.init(Cipher.ENCRYPT_MODE, aesKey);
 byte[] encrypted = cipher.doFinal(plaintext.getBytes());
 return Base64.encodeBase64String(encrypted);
}

代码示例来源:origin: org.nd4j/nd4j-base64

/**
 * Returns a tab delimited base 64
 * representation of the given arrays
 * @param arrays the arrays
 * @return
 * @throws IOException
 */
public static String arraysToBase64(INDArray[] arrays) throws IOException {
  StringBuilder sb = new StringBuilder();
  //tab separate the outputs for de serialization
  for (INDArray outputArr : arrays) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bos);
    Nd4j.write(outputArr, dos);
    String base64 = Base64.encodeBase64String(bos.toByteArray());
    sb.append(base64);
    sb.append("\t");
  }
  return sb.toString();
}

代码示例来源:origin: com.centit.support/centit-utils

/**
 * 加密方法
 * @param source
 *            源数据  加密字符串长度受秘钥长度的限制,最多加密245个字节
 * @param key 密码
 * @return 密文
 * @throws BadPaddingException 父类抛出的异常
 * @throws IllegalBlockSizeException 父类抛出的异常
 * @throws NoSuchAlgorithmException 父类抛出的异常
 * @throws NoSuchPaddingException 父类抛出的异常
 * @throws InvalidKeyException 父类抛出的异常
 */
public static String encrypt(String source,Key key) throws
    BadPaddingException, IllegalBlockSizeException,
    NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException {
  generateKeyPair();
  Key publicKey = key;
  /** 得到Cipher对象来实现对源数据的RSA加密 */
  Cipher cipher = Cipher.getInstance(ALGORITHM);
  cipher.init(Cipher.ENCRYPT_MODE, publicKey);
  byte[] b = source.getBytes();
  /** 执行加密操作 */
  byte[] b1 = cipher.doFinal(b);
  //BASE64Encoder encoder = new BASE64Encoder();
  return Base64.encodeBase64String(b1);
}

代码示例来源:origin: mustfun/mybatis-plus

public static String encrypt(byte[] keyBytes, String plainText)
    throws Exception {
  PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes);
  KeyFactory factory = KeyFactory.getInstance("RSA", "SunRsaSign");
  PrivateKey privateKey = factory.generatePrivate(spec);
  Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
  try {
    cipher.init(Cipher.ENCRYPT_MODE, privateKey);
  } catch (InvalidKeyException e) {
    //For IBM JDK, 原因请看解密方法中的说明
    RSAPrivateKey rsaPrivateKey = (RSAPrivateKey) privateKey;
    RSAPublicKeySpec publicKeySpec = new RSAPublicKeySpec(rsaPrivateKey.getModulus(), rsaPrivateKey.getPrivateExponent());
    Key fakePublicKey = KeyFactory.getInstance("RSA").generatePublic(publicKeySpec);
    cipher = Cipher.getInstance("RSA");
    cipher.init(Cipher.ENCRYPT_MODE, fakePublicKey);
  }
  byte[] encryptedBytes = cipher.doFinal(plainText.getBytes("UTF-8"));
  String encryptedString = Base64.encodeBase64String(encryptedBytes);
  return encryptedString;
}

代码示例来源:origin: apache/tajo

case BLOB:
case VARBINARY:
 json.put(fieldName,  Base64.encodeBase64String(input.getBytes(fieldIndex)));
 break;

代码示例来源:origin: org.apache.tajo/tajo-storage-hdfs

case BLOB:
case VARBINARY:
 json.put(fieldName,  Base64.encodeBase64String(input.getBytes(fieldIndex)));
 break;

相关文章