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


Java Base64.getEncoder方法代码示例

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


在下文中一共展示了Base64.getEncoder方法的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: test

import java.util.Base64; //导入方法依赖的package包/类
@Test(timeout = 7500)
public void test() throws IOException {
	//FIXME 无法执行。存在405错误。
	Base64.Encoder encoder = Base64.getEncoder();
	Connection con = Jsoup.connect("http://localhost/api/v0/auth/check_cert")
			.data("uname", encoder.encodeToString("磷".getBytes(StandardCharsets.UTF_8)))
			.data("email", encoder.encodeToString("[email protected]".getBytes(StandardCharsets.UTF_8)))
			.data("zhihu", encoder.encodeToString("ice1000".getBytes(StandardCharsets.UTF_8)))
			.data("github", encoder.encodeToString("Ray-Eldath".getBytes(StandardCharsets.UTF_8)))
			.data("stackoverflow", encoder.encodeToString("VonC".getBytes(StandardCharsets.UTF_8)))
			.data("brief", encoder.encodeToString("测试".getBytes(StandardCharsets.UTF_8)))
			.data("introduce", encoder.encodeToString("测试lalala".getBytes(StandardCharsets.UTF_8)))
			.timeout(8000);
	Document doc = con.get();
	System.out.println(doc.text());
}
 
开发者ID:ProgramLeague,项目名称:strictfp-back-end,代码行数:17,代码来源:CheckCert.java

示例3: 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

示例4: encryptData_CBC

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

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

        SM4 sm4 = new SM4();
        sm4.sm4_setkey_enc(ctx, keyBytes);
        byte[] encrypted = sm4.sm4_crypt_cbc(ctx, ivBytes, plainText.getBytes("UTF-8"));
        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,代码行数:32,代码来源:SM4Utils.java

示例5: main

import java.util.Base64; //导入方法依赖的package包/类
public static void main(String[] args){
    KeyPairGenerator kpg = null;
    try{
        kpg = KeyPairGenerator.getInstance("RSA");
    } catch(NoSuchAlgorithmException ex){
        log.error(ex, ex);
        throw new RuntimeException(ex);
    }
    kpg.initialize(1024);
    KeyPair keyPair = kpg.generateKeyPair();
    Key privateKey = keyPair.getPrivate();
    Key publicKey = keyPair.getPublic();
    
    Base64.Encoder encoder = Base64.getEncoder();
    String privateKeyBase64Str = encoder.encodeToString(privateKey.getEncoded());
    log.info("Private key in Base64 format:\n" + privateKeyBase64Str);//it creates 1623 chars or 1620 chars
    
    Base64.Decoder decoder = Base64.getDecoder();
    byte[] privateKeyBytes = decoder.decode(privateKeyBase64Str);
    log.info("The private Key is " + privateKeyBytes.length + " bytes long");
    String privateKeyHex = String.format("%040x", new BigInteger(1, privateKeyBytes));
    log.info("The private key in hexadecimal digits:\n" + privateKeyHex);
    
    
    String publicKeyBase64Str = encoder.encodeToString(publicKey.getEncoded());
    log.info("Public key in Base64 format:\n" + publicKeyBase64Str);//it creates 392 chars and again 392 chars for 2048 bits
                                                                    //it creates 162 bytes for 1024 bits, an Ethereum address is 20 bytes (40 hexadecimal digits/characters long)
                                                                    //324 hexadecimal characters, and we use the last 40 as the Ethereum address
    byte[] publicKeyBytes = decoder.decode(publicKeyBase64Str);
    log.info("The public Key is " + publicKeyBytes.length + " bytes long");
    String publicKeyHex = String.format("%040x", new BigInteger(1, publicKeyBytes));
    log.info("The public key in hexadecimal digits:\n" + publicKeyHex);
}
 
开发者ID:VictorGil,项目名称:shared-ledger-simulator,代码行数:34,代码来源:KeyGenerationTester.java

示例6: GLProof

import java.util.Base64; //导入方法依赖的package包/类
public GLProof(GLRSSSignatureOutput.GLRSSSignedPart signedPart) {
    Base64.Encoder encoder = Base64.getEncoder();
    this.randomValue = encoder.encodeToString(signedPart.getRandomValue());
    this.accumulatorValue = encoder.encodeToString(signedPart.getAccumulatorValue());
    this.gsProof = encoder.encodeToString(signedPart.getGsProof());
    for (ByteArray byteArray : signedPart.getWitnesses()) {
        witnesses.add(encoder.encodeToString(byteArray.getArray()));
    }
}
 
开发者ID:woefe,项目名称:xmlrss,代码行数:10,代码来源:GLProof.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:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:31,代码来源:TestBase64.java

示例8: 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

示例9: 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

示例10: 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

示例11: encrypt

import java.util.Base64; //导入方法依赖的package包/类
/**
 * Encrypts given password with secret key
 * @param plainText
 * @return
 * @throws Exception
 */
public String encrypt(String plainText) throws Exception
{
    logger.debug("Encryption algo running");
    Cipher cipher = Cipher.getInstance(ALGO + "/" + MODE + "/" + PADDING);
    byte[] plainTextByte = plainText.getBytes();
    cipher.init(Cipher.ENCRYPT_MODE, key);
    byte[] encryptedByte = cipher.doFinal(plainTextByte);

    Base64.Encoder encoder = Base64.getEncoder();
    String encryptedText = encoder.encodeToString(encryptedByte);
    logger.debug("Encryption algo executed");
    return encryptedText;
}
 
开发者ID:Vedang18,项目名称:ProBOT,代码行数:20,代码来源:PasswordCoder.java

示例12: ExerciseExporter

import java.util.Base64; //导入方法依赖的package包/类
public ExerciseExporter(String boltUri, AuthToken authToken) {
    this.boltUri = boltUri;
    this.authToken = authToken;
    kryo = new Kryo();
    encoder = Base64.getEncoder();
}
 
开发者ID:fbiville,项目名称:hands-on-neo4j-devoxx-fr-2017,代码行数:7,代码来源:ExerciseExporter.java

示例13: putFile

import java.util.Base64; //导入方法依赖的package包/类
public static void putFile(DbfsClient client,
                           File file,
                           String path,
                           boolean overwrite) throws FileNotFoundException, IOException, HttpException {

    FileInputStream fileInputStreamReader = new FileInputStream(file);
    try {
        byte[] fileBytes = new byte[(int)file.length()];
        fileInputStreamReader.read(fileBytes);
        //System.out.println("Total Num of raw Bytes from File=" + file.length());

        //encode bytes to Base64
        Base64.Encoder encoder = Base64.getEncoder();
        byte[] fileBase64Bytes = encoder.encode(fileBytes);

        long bytesLeftToSend = fileBase64Bytes.length;
        //System.out.println("Total Num of Base64 Bytes to Send="+bytesLeftToSend);
        //TODO add call to .put() if less than MAX_BLOCK_SIZE

        //open handler to DBFS
        long dbfsHandle = client.create(path, overwrite);

        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(fileBase64Bytes);

        while(bytesLeftToSend > 0) {
            int numBytesToSend = (int) bytesLeftToSend > MAX_BLOCK_SIZE ? MAX_BLOCK_SIZE : (int) bytesLeftToSend;
            byte[] bytesToSend = new byte[(int)numBytesToSend];

            //read the next batch of bytes that fits into the byte array
            int numBytesRead = byteArrayInputStream.read(bytesToSend);

            //TODO add retry logic; inside or outside the client?

            //add block to DBFS
            //System.out.println("BEFORE addBlock; base64Bytes="+numBytesToSend);
            client.addBlock(dbfsHandle, bytesToSend);

            bytesLeftToSend = bytesLeftToSend - numBytesRead;
        }
        //close handler to DBFS
        client.close(dbfsHandle);
    } catch (Throwable e) {
      throw e;
    } finally {
        fileInputStreamReader.close();
    }

}
 
开发者ID:level11data,项目名称:databricks-client-java,代码行数:49,代码来源:DbfsHelper.java

示例14: readXmlFile

import java.util.Base64; //导入方法依赖的package包/类
private String readXmlFile(String xmlFile) throws IOException, URISyntaxException {
    Base64.Encoder encoder = Base64.getEncoder();
    URL resource = getClass().getClassLoader().getResource(xmlFile);
    return new String(encoder.encode(Files.readAllBytes(Paths.get(resource.toURI()))));
}
 
开发者ID:alphagov,项目名称:verify-hub,代码行数:6,代码来源:ProtectiveMonitoringLogFormatterTest.java

示例15: 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


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