當前位置: 首頁>>代碼示例>>Java>>正文


Java DatatypeConverter.printBase64Binary方法代碼示例

本文整理匯總了Java中javax.xml.bind.DatatypeConverter.printBase64Binary方法的典型用法代碼示例。如果您正苦於以下問題:Java DatatypeConverter.printBase64Binary方法的具體用法?Java DatatypeConverter.printBase64Binary怎麽用?Java DatatypeConverter.printBase64Binary使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.xml.bind.DatatypeConverter的用法示例。


在下文中一共展示了DatatypeConverter.printBase64Binary方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: EncryptAES

import javax.xml.bind.DatatypeConverter; //導入方法依賴的package包/類
public static String EncryptAES(String input, SecretKey key) throws CryptoException {
    // encode input
    input = DatatypeConverter.printBase64Binary(input.getBytes());

    byte[] ciphertext = null;
    try {
        ciphertext = AES.encrypt(input.getBytes(), key);
    } catch (Exception e) {
        throw new CryptoException(e);
    }


    // encode encrypted input
    //return DatatypeConverter.printBase64Binary(ciphertext.getBytes());
    return DatatypeConverter.printHexBinary(ciphertext);
}
 
開發者ID:richkmeli,項目名稱:Richkware-Manager-Client,代碼行數:17,代碼來源:Crypto.java

示例2: encodeToString

import javax.xml.bind.DatatypeConverter; //導入方法依賴的package包/類
/**
 * Base64-encode the given byte array to a String.
 * 
 * @param src
 *            the original byte array (may be {@code null})
 * @return the encoded byte array as a UTF-8 String (or {@code null} if the
 *         input was {@code null})
 */
public static String encodeToString(byte[] src) {
	if (src == null) {
		return null;
	}
	if (src.length == 0) {
		return "";
	}

	if (delegate != null) {
		// Full encoder available
		return new String(delegate.encode(src), DEFAULT_CHARSET);
	} else {
		// JAXB fallback for String case
		return DatatypeConverter.printBase64Binary(src);
	}
}
 
開發者ID:zhangjunfang,項目名稱:util,代碼行數:25,代碼來源:Base64Utils.java

示例3: encrypt

import javax.xml.bind.DatatypeConverter; //導入方法依賴的package包/類
/**
 * Encrypt plaintext.
 * @param str Plaintext to encrypt
 * @return Cipher text
 */
public String encrypt(final String str) {
    if (str == null) {
        throw new NullPointerException("Argument cannot be null");
    }

    try {
        final SecureRandom random = new SecureRandom();
        final byte[] salt = new byte[16];
        random.nextBytes(salt);

        final SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
        final KeySpec spec = new PBEKeySpec(passphrase.toCharArray(), salt, 65536, 128);
        final SecretKey tmp = factory.generateSecret(spec);
        final SecretKey secret = new SecretKeySpec(tmp.getEncoded(), "AES");

        final Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        cipher.init(Cipher.ENCRYPT_MODE, secret);

        final AlgorithmParameters params = cipher.getParameters();
        final byte[] iv = params.getParameterSpec(IvParameterSpec.class).getIV();
        final byte[] encryptedText = cipher.doFinal(str.getBytes(StandardCharsets.UTF_8));

        // concatenate salt + iv + ciphertext
        final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        outputStream.write(salt);
        outputStream.write(iv);
        outputStream.write(encryptedText);

        // properly encode the complete cipher text
        return DatatypeConverter.printBase64Binary(outputStream.toByteArray());
    } catch (final Exception exception) {
        throw new RuntimeException(exception.getMessage(), exception);
    }
}
 
開發者ID:SourceLabOrg,項目名稱:kafka-webview,代碼行數:40,代碼來源:SecretManager.java

示例4: addBasicAuth

import javax.xml.bind.DatatypeConverter; //導入方法依賴的package包/類
private void addBasicAuth(Packet context, Map<String, List<String>> reqHeaders) {
    String user = (String) context.invocationProperties.get(BindingProvider.USERNAME_PROPERTY);
    if (user != null) {
        String pw = (String) context.invocationProperties.get(BindingProvider.PASSWORD_PROPERTY);
        if (pw != null) {
            StringBuilder buf = new StringBuilder(user);
            buf.append(":");
            buf.append(pw);
            String creds = DatatypeConverter.printBase64Binary(buf.toString().getBytes());
            reqHeaders.put("Authorization", Collections.singletonList("Basic "+creds));
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:HttpTransportPipe.java

示例5: send

import javax.xml.bind.DatatypeConverter; //導入方法依賴的package包/類
public void send(EmailModel model) throws VaVedemEmailException {
    Email from = new Email(model.getFrom());
    String subject = model.getSubject();
    Email to = new Email(model.getTo());
    Content content = new Content("text/plain", model.getContent());
    Mail mail = new Mail(from, subject, to, content);

    Map<String, String> fileNames = listFormulare(formulareDir);
    final String formular = model.getFormular();
    final String fileName = fileNames.get(formular);

    if (StringUtils.isBlank(fileName) && StringUtils.isNotBlank(formular)) {
        logger.error("[VaVedem] :  formularul : " + formular + " nu a fost gasit pe disk. ");
        throw new VaVedemEmailException("Eroare la trimiterea emailului.");
    }

    String base64 = null;
    try {
        base64 = DatatypeConverter.printBase64Binary(Files.readAllBytes(
                Paths.get(fileName)));
    } catch (IOException e) {
        logger.error("[VaVedem] Eroare la conversia in base64 a fisierului: " + fileName);
        throw new VaVedemEmailException("Eroare la trimiterea emailului.");
    }

    Attachments ats = new Attachments();
    ats.setContent(base64);
    ats.setFilename(formular);

    mail.addAttachments(ats);

    SendGrid sg = new SendGrid(sendGridApiKey);
    System.out.println("LOG [VaVedem] :  send grid api-key: " + sendGridApiKey);
    Request request = new Request();
    try {
        request.setMethod(Method.POST);
        request.setEndpoint("mail/send");
        request.setBody(mail.build());
        Response response = sg.api(request);
    } catch (IOException ex) {
        ex.printStackTrace();
        throw new VaVedemEmailException("Eroare la trimiterea emailului.");
    }
}
 
開發者ID:CoruptiaUcide,項目名稱:va-vedem-api,代碼行數:45,代碼來源:EmailService.java

示例6: sendItemStackToClient

import javax.xml.bind.DatatypeConverter; //導入方法依賴的package包/類
protected static void sendItemStackToClient(EntityPlayerMP player, MalmoMessageType message, ItemStack is)
{
    ByteBuf buf = Unpooled.buffer();
    ByteBufUtils.writeItemStack(buf, is);
    byte[] bytes = new byte[buf.readableBytes()];
    buf.getBytes(0, bytes);
    String data = DatatypeConverter.printBase64Binary(bytes);
    MalmoMod.MalmoMessage msg = new MalmoMod.MalmoMessage(message, data);
    MalmoMod.network.sendTo(msg, player);
}
 
開發者ID:Yarichi,項目名稱:Proyecto-DASI,代碼行數:11,代碼來源:RewardForItemBase.java

示例7: sign

import javax.xml.bind.DatatypeConverter; //導入方法依賴的package包/類
public static String sign(byte[] plainText, PrivateKey privateKey) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException {
    Signature privateSignature = Signature.getInstance(signVerifyAlgorithm);
    privateSignature.initSign(privateKey);
    privateSignature.update(plainText);

    return DatatypeConverter.printBase64Binary(privateSignature.sign());
}
 
開發者ID:richkmeli,項目名稱:Richkware-Manager-Client,代碼行數:8,代碼來源:RSA.java

示例8: encodeImg2String

import javax.xml.bind.DatatypeConverter; //導入方法依賴的package包/類
/**
 * Encodes the given image to a base64 coded string.
 *
 * @param image image to encode
 * @param type type of the image: jpeg, bmp, png, gif etc.
 * @return encoded string
 */
public static String encodeImg2String(BufferedImage image, String type) {
    String imageString = null;
    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    try {
        ImageIO.write(image, type, bos);
        byte[] imageBytes = bos.toByteArray();
        imageString = DatatypeConverter.printBase64Binary(imageBytes);
        bos.close();
    } catch (IOException ex) {
        LOGGER.error(ex.getMessage(), ex);
    }
    return imageString;
}
 
開發者ID:vrk-kpa,項目名稱:xrd4j,代碼行數:22,代碼來源:MessageHelper.java

示例9: deflateAndBase64

import javax.xml.bind.DatatypeConverter; //導入方法依賴的package包/類
private String deflateAndBase64(final String data) {
    try {
        final Deflater deflater = new Deflater();
        deflater.setInput(data.getBytes(HttpConstants.UTF8_ENCODING));
        deflater.finish();
        final byte[] buffer = new byte[data.length()];
        final int resultSize = deflater.deflate(buffer);
        final byte[] output = new byte[resultSize];
        System.arraycopy(buffer, 0, output, 0, resultSize);
        return DatatypeConverter.printBase64Binary(output);
    } catch (final UnsupportedEncodingException e) {
        throw new RuntimeException("Cannot find encoding:" + HttpConstants.UTF8_ENCODING, e);
    }
}
 
開發者ID:yaochi,項目名稱:pac4j-plus,代碼行數:15,代碼來源:CasClientTests.java

示例10: generateChallenge

import javax.xml.bind.DatatypeConverter; //導入方法依賴的package包/類
private String generateChallenge() {
    byte[] challengeBytes = CryptoUtil.secureRandom(16);
    currentChallenge = DatatypeConverter.printBase64Binary(challengeBytes);
    return currentChallenge;
}
 
開發者ID:xuraylei,項目名稱:fresco_floodlight,代碼行數:6,代碼來源:AbstractRPCChannelHandler.java

示例11: toBase64

import javax.xml.bind.DatatypeConverter; //導入方法依賴的package包/類
private static String toBase64(byte[] array) {
	return DatatypeConverter.printBase64Binary(array);
}
 
開發者ID:topicquests,項目名稱:backside-servlet-ks,代碼行數:4,代碼來源:PasswordStorage.java

示例12: getBasicAuthHeader

import javax.xml.bind.DatatypeConverter; //導入方法依賴的package包/類
private static String getBasicAuthHeader(String username, String password) throws UnsupportedEncodingException {
   return "Basic " + DatatypeConverter.printBase64Binary((username + ":" + password).getBytes("UTF-8"));
}
 
開發者ID:acciente,項目名稱:oacc-example-securetodo,代碼行數:4,代碼來源:TodoItemResourceTest.java

示例13: getKeyAsString

import javax.xml.bind.DatatypeConverter; //導入方法依賴的package包/類
private String getKeyAsString(ByteArray key) 
        throws UnsupportedEncodingException {
    return DatatypeConverter.printBase64Binary(key.get());
}
 
開發者ID:xuraylei,項目名稱:fresco_floodlight,代碼行數:5,代碼來源:JavaDBStorageEngine.java

示例14: getSecret

import javax.xml.bind.DatatypeConverter; //導入方法依賴的package包/類
/**
 * Creates the secret key from a static string
 * 
 * @return byte[] conversion of secretKey
 */
private static byte[] getSecret() {
	String base64Key = DatatypeConverter.printBase64Binary(secretKey.getBytes());
	
	return DatatypeConverter.parseBase64Binary(base64Key);
}
 
開發者ID:grantleymorrison,項目名稱:FlashBoard,代碼行數:11,代碼來源:TokenService.java

示例15: toMessage

import javax.xml.bind.DatatypeConverter; //導入方法依賴的package包/類
String toMessage() {
    if (error != null)
        return "e=" + error;
    else
        return "v=" + DatatypeConverter.printBase64Binary(serverSignature);
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:7,代碼來源:ScramMessages.java


注:本文中的javax.xml.bind.DatatypeConverter.printBase64Binary方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。