当前位置: 首页>>代码示例>>Java>>正文


Java Base64.Encoder方法代码示例

本文整理汇总了Java中java.util.Base64.Encoder方法的典型用法代码示例。如果您正苦于以下问题:Java Base64.Encoder方法的具体用法?Java Base64.Encoder怎么用?Java Base64.Encoder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Base64的用法示例。


在下文中一共展示了Base64.Encoder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import java.util.Base64; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    InputStream is = EncodeJsonConfig.class.getResourceAsStream("/master.json");
    byte[] tmp = new byte[1024];
    int length = is.read(tmp);
    while (length > 0) {
        baos.write(tmp, 0, length);
        length = is.read(tmp);
    }
    is.close();
    baos.close();
    tmp = baos.toByteArray();
    Base64.Encoder encoder = Base64.getEncoder();
    String encoded = encoder.encodeToString(tmp);
    System.out.printf("  sso-demo.json: %s\n", encoded);
}
 
开发者ID:obsidian-toaster-quickstarts,项目名称:redhat-sso,代码行数:17,代码来源:EncodeJsonConfig.java

示例2: testEncodeToStringWithLongInputData

import java.util.Base64; //导入方法依赖的package包/类
private static void testEncodeToStringWithLongInputData(
        final Base64.Encoder encoder) {
    System.err.println("\n\nEncoder.encodeToStringWithLongInputData test  ");

    final byte[] secondTestBuffer =
            "api/java_util/Base64/index.html#GetEncoderMimeCustom[noLineSeparatorInEncodedString]"
            .getBytes(US_ASCII);
    String base64EncodedString;
    base64EncodedString = encoder.encodeToString(secondTestBuffer);

    System.err.println("Second Base64 encoded string is "
            + base64EncodedString);

    if (base64EncodedString.contains("$$$")) {
        throw new RuntimeException(
                "Base64 encoding contains line separator after encodeToString invoked  ... \n");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:Base64GetEncoderTest.java

示例3: testWrapEncode1

import java.util.Base64; //导入方法依赖的package包/类
private static void testWrapEncode1(final Base64.Encoder encoder)
        throws IOException {
    System.err.println("\nEncoder.wrap test I ");

    final byte[] bytesIn = "fo".getBytes(US_ASCII);
    String base64EncodedString;
    ByteArrayOutputStream encodingStream = new ByteArrayOutputStream();
    OutputStream encoding = encoder.wrap(encodingStream);
    encoding.write(bytesIn);
    encoding.close();

    final byte[] encodedBytes = encodingStream.toByteArray();

    System.err.print("result = " + new String(encodedBytes, US_ASCII)
            + "  after the Base64 encoding \n");

    base64EncodedString = new String(encodedBytes, US_ASCII);

    if (base64EncodedString.contains("$$$")) {
        throw new RuntimeException(
                "Base64 encoding contains line separator after wrap I test ... \n");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:Base64GetEncoderTest.java

示例4: testWrapEncode2

import java.util.Base64; //导入方法依赖的package包/类
private static void testWrapEncode2(final Base64.Encoder encoder)
        throws IOException {
    System.err.println("\nEncoder.wrap test II ");
    final byte[] secondTestBuffer =
            "api/java_util/Base64/index.html#GetEncoderMimeCustom[noLineSeparatorInEncodedString]"
            .getBytes(US_ASCII);
    String base64EncodedString;
    ByteArrayOutputStream secondEncodingStream = new ByteArrayOutputStream();
    OutputStream base64EncodingStream = encoder.wrap(secondEncodingStream);
    base64EncodingStream.write(secondTestBuffer);
    base64EncodingStream.close();

    final byte[] encodedByteArray = secondEncodingStream.toByteArray();

    System.err.print("result = " + new String(encodedByteArray, US_ASCII)
            + "  after wrap Base64 encoding of string");

    base64EncodedString = new String(encodedByteArray, US_ASCII);

    if (base64EncodedString.contains("$$$")) {
        throw new RuntimeException(
                "Base64 encoding contains line separator after wrap 2 invoked  ... \n");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:Base64GetEncoderTest.java

示例5: encryptData_ECB

import java.util.Base64; //导入方法依赖的package包/类
public String encryptData_ECB(String plainText) {
    try {
        SM4_Context ctx = new SM4_Context();
        ctx.isPadding = true;
        ctx.mode = SM4.SM4_ENCRYPT;

        byte[] keyBytes;
        if (hexString) {
            keyBytes = Util.hexStringToBytes(secretKey);
        } else {
            keyBytes = secretKey.getBytes();
        }

        SM4 sm4 = new SM4();
        sm4.sm4_setkey_enc(ctx, keyBytes);
        byte[] encrypted = sm4.sm4_crypt_ecb(ctx, plainText.getBytes("GBK"));
        Base64.Encoder encoder = Base64.getEncoder();
        String cipherText = encoder.encodeToString(encrypted);
        if (cipherText != null && cipherText.trim().length() > 0) {

            Matcher m = PATTERN_1.matcher(cipherText);
            cipherText = m.replaceAll("");
        }
        return cipherText;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
开发者ID:nuls-io,项目名称:nuls,代码行数:30,代码来源:SM4Utils.java

示例6: encode

import java.util.Base64; //导入方法依赖的package包/类
public String encode(BufferedImage image) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(image, "jpeg", baos);
    byte[] bytes = baos.toByteArray();
    Base64.Encoder encoder = Base64.getEncoder();
    String imgstr = encoder.encodeToString(bytes);
    return imgstr;
}
 
开发者ID:FlyingHe,项目名称:UtilsMaven,代码行数:9,代码来源:TestImgCompress.java

示例7: testDecodeIgnoredAfterPadding

import java.util.Base64; //导入方法依赖的package包/类
private static void testDecodeIgnoredAfterPadding() throws Throwable {
    for (byte nonBase64 : new byte[] {'#', '(', '!', '\\', '-', '_', '\n', '\r'}) {
        byte[][] src = new byte[][] {
            "A".getBytes("ascii"),
            "AB".getBytes("ascii"),
            "ABC".getBytes("ascii"),
            "ABCD".getBytes("ascii"),
            "ABCDE".getBytes("ascii")
        };
        Base64.Encoder encM = Base64.getMimeEncoder();
        Base64.Decoder decM = Base64.getMimeDecoder();
        Base64.Encoder enc = Base64.getEncoder();
        Base64.Decoder dec = Base64.getDecoder();
        for (int i = 0; i < src.length; i++) {
            // decode(byte[])
            byte[] encoded = encM.encode(src[i]);
            encoded = Arrays.copyOf(encoded, encoded.length + 1);
            encoded[encoded.length - 1] = nonBase64;
            checkEqual(decM.decode(encoded), src[i], "Non-base64 char is not ignored");
            byte[] decoded = new byte[src[i].length];
            decM.decode(encoded, decoded);
            checkEqual(decoded, src[i], "Non-base64 char is not ignored");

            try {
                dec.decode(encoded);
                throw new RuntimeException("No IAE for non-base64 char");
            } catch (IllegalArgumentException iae) {}
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:TestBase64.java

示例8: getSettingsString

import java.util.Base64; //导入方法依赖的package包/类
/** Returns the client settings as a base64 (url) encoded string */
String getSettingsString() {
    SettingsFrame sf = getClientSettings();
    byte[] settings = sf.toByteArray(); // without the header
    Base64.Encoder encoder = Base64.getUrlEncoder()
                                   .withoutPadding();
    return encoder.encodeToString(settings);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:Http2ClientImpl.java

示例9: testVerifyCodeBase64

import java.util.Base64; //导入方法依赖的package包/类
@Test
public void testVerifyCodeBase64() throws IOException {
    VerificationCodeImage codeImage = new VerificationCodeImage();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(codeImage.getImage(), "jpeg", baos);
    byte[] bytes = baos.toByteArray();
    Base64.Encoder encoder = Base64.getEncoder();
    String imgstr = encoder.encodeToString(bytes);
    System.out.println(imgstr);
}
 
开发者ID:FlyingHe,项目名称:UtilsMaven,代码行数:11,代码来源:TestImgCompress.java

示例10: testIOE

import java.util.Base64; //导入方法依赖的package包/类
private static void testIOE(Base64.Encoder enc) throws Throwable {
    ByteArrayOutputStream baos = new ByteArrayOutputStream(8192);
    OutputStream os = enc.wrap(baos);
    os.write(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9});
    os.close();
    checkIOE(() -> os.write(10));
    checkIOE(() -> os.write(new byte[] {10}));
    checkIOE(() -> os.write(new byte[] {10}, 1, 4));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:TestBase64.java

示例11: testEncode

import java.util.Base64; //导入方法依赖的package包/类
private static final void testEncode(Base64.Encoder enc, ByteBuffer bin, byte[] expected)
    throws Throwable {

    ByteBuffer bout = enc.encode(bin);
    byte[] buf = new byte[bout.remaining()];
    bout.get(buf);
    if (bin.hasRemaining()) {
        throw new RuntimeException(
            "Base64 enc.encode(ByteBuffer) failed!");
    }
    checkEqual(buf, expected, "Base64 enc.encode(bf, bf) failed!");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:TestBase64.java

示例12: testEncoderKeepsSilence

import java.util.Base64; //导入方法依赖的package包/类
private static void testEncoderKeepsSilence(Base64.Encoder enc)
        throws Throwable {
    List<Integer> vals = Arrays.asList(Integer.MIN_VALUE,
            Integer.MIN_VALUE + 1, -1111, -2, -1, 0, 1, 2, 3, 1111,
            Integer.MAX_VALUE - 1, Integer.MAX_VALUE,
            rnd.nextInt(), rnd.nextInt(), rnd.nextInt(),
            rnd.nextInt());
    byte[] buf = new byte[] {1, 0, 91};
    for (int off : vals) {
        for (int len : vals) {
            if (off >= 0 && len >= 0 && off <= buf.length - len) {
                // valid args, skip them
                continue;
            }
            // invalid args, test them
            System.out.println("testing off=" + off + ", len=" + len);

            ByteArrayOutputStream baos = new ByteArrayOutputStream(100);
            try (OutputStream os = enc.wrap(baos)) {
                os.write(buf, off, len);
                throw new RuntimeException("Expected IOOBEx was not thrown");
            } catch (IndexOutOfBoundsException expected) {
            }
            if (baos.size() > 0)
                throw new RuntimeException("No output was expected, but got "
                        + baos.size() + " bytes");
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:30,代码来源:TestBase64.java

示例13: encrypt

import java.util.Base64; //导入方法依赖的package包/类
public String encrypt(String plainText)throws Exception 
{
byte [] plainTextByte = plainText.getBytes();
       cpr.init(Cipher.ENCRYPT_MODE, sk);
       byte [] encryptedByte = cpr.doFinal(plainTextByte);
       Base64.Encoder encoder = Base64.getEncoder();
       String encryptedText = encoder.encodeToString(encryptedByte);
       String encryptedKey = encoder.encodeToString(sk.getEncoded());
       return (encryptedText+"\n"+encryptedKey+"\n");
}
 
开发者ID:Tejas07PSK,项目名称:maven_EWorld_OpenShift,代码行数:11,代码来源:AES.java

示例14: GSSignatureValue

import java.util.Base64; //导入方法依赖的package包/类
public GSSignatureValue(byte[] dsigValue, byte[] accumulatorValue) {
    Base64.Encoder encoder = Base64.getEncoder();
    this.dsigValue = encoder.encodeToString(dsigValue);
    this.accumulatorValue = encoder.encodeToString(accumulatorValue);
}
 
开发者ID:woefe,项目名称:xmlrss,代码行数:6,代码来源:GSSignatureValue.java

示例15: modifyBytes

import java.util.Base64; //导入方法依赖的package包/类
public byte[] modifyBytes(byte[] input) {
    Base64.Encoder encoder = Base64.getEncoder();
    return encoder.encode(input);
}
 
开发者ID:nccgroup,项目名称:Decoder-Improved,代码行数:5,代码来源:Base64Encoder.java


注:本文中的java.util.Base64.Encoder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。