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


Java Base64.Decoder方法代码示例

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


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

示例1: decryptData_ECB

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

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

        SM4 sm4 = new SM4();
        sm4.sm4_setkey_dec(ctx, keyBytes);
        Base64.Decoder decoder = Base64.getDecoder();
        byte[] decrypted = sm4.sm4_crypt_ecb(ctx, decoder.decode(cipherText));
        return new String(decrypted, "UTF-8");
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
开发者ID:nuls-io,项目名称:nuls,代码行数:24,代码来源:SM4Utils.java

示例2: decryptData_CBC

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

        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_dec(ctx, keyBytes);
        Base64.Decoder decoder = Base64.getDecoder();
        byte[] decrypted = sm4.sm4_crypt_cbc(ctx, ivBytes, decoder.decode(cipherText));
        return new String(decrypted, "UTF-8");
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
开发者ID:nuls-io,项目名称:nuls,代码行数:26,代码来源:SM4Utils.java

示例3: testDecodeUnpadded

import java.util.Base64; //导入方法依赖的package包/类
private static void  testDecodeUnpadded() throws Throwable {
    byte[] srcA = new byte[] { 'Q', 'Q' };
    byte[] srcAA = new byte[] { 'Q', 'Q', 'E'};
    Base64.Decoder dec = Base64.getDecoder();
    byte[] ret = dec.decode(srcA);
    if (ret[0] != 'A')
        throw new RuntimeException("Decoding unpadding input A failed");
    ret = dec.decode(srcAA);
    if (ret[0] != 'A' && ret[1] != 'A')
        throw new RuntimeException("Decoding unpadding input AA failed");
    ret = new byte[10];
    if (dec.wrap(new ByteArrayInputStream(srcA)).read(ret) != 1 &&
        ret[0] != 'A')
        throw new RuntimeException("Decoding unpadding input A from stream failed");
    if (dec.wrap(new ByteArrayInputStream(srcA)).read(ret) != 2 &&
        ret[0] != 'A' && ret[1] != 'A')
        throw new RuntimeException("Decoding unpadding input AA from stream failed");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:TestBase64.java

示例4: main

import java.util.Base64; //导入方法依赖的package包/类
public static void main(String[] args) {
    Base64.Decoder b64decoder = Base64.getUrlDecoder();
    final Undertow server = Undertow.builder()
            .addHttpListener(8083, "localhost")
            .setHandler(exchange -> {
                exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
                String credential = exchange.getRequestHeaders().getFirst("X-Bouncr-Credential");
                String[] tokens = credential.split("\\.", 3);
                String json = new String(b64decoder.decode(tokens[1]));


                exchange.getResponseSender().send("Server1\n"
                        + "profile=" + json + "\n"
                );
            })
            .build();
    Runtime.getRuntime().addShutdownHook(new Thread(server::stop));
    server.start();
}
 
开发者ID:kawasima,项目名称:bouncr,代码行数:20,代码来源:ForTestBackendApp.java

示例5: parseDerKeySpec

import java.util.Base64; //导入方法依赖的package包/类
public static DerKeySpec parseDerKeySpec(String rawKeyString) {
  try {
    // Base64 decode the data
    Base64.Decoder b64decoder = Base64.getDecoder();
    byte[] encoded =
        b64decoder.decode(
            rawKeyString
                .replace("-----BEGIN RSA PRIVATE KEY-----\n", "")
                .replace("-----END RSA PRIVATE KEY-----\n", "")
                .replace("\n", ""));

    DerInputStream derReader = new DerInputStream(encoded);
    DerValue[] seq = derReader.getSequence(0);

    if (seq.length != 9) {
      throw new RuntimeException(
          new GeneralSecurityException("Could not parse a PKCS1 private key."));
    }

    DerKeySpec ks = new DerKeySpec();

    ks.version = seq[0].getBigInteger();
    ks.modulus = seq[1].getBigInteger();
    ks.publicExp = seq[2].getBigInteger();
    ks.privateExp = seq[3].getBigInteger();
    ks.prime1 = seq[4].getBigInteger();
    ks.prime2 = seq[5].getBigInteger();
    ks.exp1 = seq[6].getBigInteger();
    ks.exp2 = seq[7].getBigInteger();
    ks.crtCoef = seq[8].getBigInteger();

    return ks;
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:Nordstrom,项目名称:xrpc,代码行数:37,代码来源:X509CertificateGenerator.java

示例6: getObject

import java.util.Base64; //导入方法依赖的package包/类
public static byte[] getObject(DbfsClient client, String path) throws IOException, HttpException {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    try {
        FileInfoDTO statusResponseDTO = client.getStatus(path);
        long bytesLeftToRead = statusResponseDTO.FileSize;

        long offset = 0;

        while(bytesLeftToRead > 0) {
            ReadResponseDTO readResponseDTO = client.read(path, offset, MAX_BLOCK_SIZE);
            long numBytesRead = readResponseDTO.BytesRead;

            //System.out.println("bytesLeftToRead: "+bytesLeftToRead + ", numBytesRead: "+numBytesRead);

            Base64.Decoder decoder = Base64.getDecoder();
            byte[] decodedBytes = decoder.decode(readResponseDTO.data);
            outputStream.write(decodedBytes);
            bytesLeftToRead = bytesLeftToRead - numBytesRead;
            offset = offset + numBytesRead;
        }
        return outputStream.toByteArray();
    } catch(Throwable e) {
        throw e;
    } finally {
        outputStream.close();
    }
}
 
开发者ID:level11data,项目名称:databricks-client-java,代码行数:29,代码来源:DbfsHelper.java

示例7: createPublicKey

import java.util.Base64; //导入方法依赖的package包/类
static PublicKey createPublicKey(String modulus, String exponent) throws InvalidKeySpecException, NoSuchAlgorithmException
{
    Base64.Decoder decoder = Base64.getDecoder();
    BigInteger bigModulus = new BigInteger(1, decoder.decode(modulus));
    BigInteger bigExponent = new BigInteger(1, decoder.decode(exponent));
    RSAPublicKeySpec publicKeySpec = new RSAPublicKeySpec(bigModulus, bigExponent);
    KeyFactory keyFactory = KeyFactory.getInstance("RSA");

    return keyFactory.generatePublic(publicKeySpec);
}
 
开发者ID:curityio,项目名称:oauth-filter-for-java,代码行数:11,代码来源:RsaPublicKeyCreator.java

示例8: getPNGData

import java.util.Base64; //导入方法依赖的package包/类
private byte[] getPNGData(Picture picture, double width, double height) {
    Base64.Decoder decoder = Base64.getDecoder();
    byte[] decoded = decoder.decode(picture.getContent());

    if (picture.getType() == ImageType.SVG) {
        ByteArrayOutputStream pngStream = new ByteArrayOutputStream();
        //svgConverter.convertSvgToPng(new ByteArrayInputStream(decoded), pngStream, (float)width, (float)height);
        svgConverter.convertSvgToEmf(new ByteArrayInputStream(decoded), pngStream);

        return pngStream.toByteArray();
    } else {
        return decoded;
    }
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:15,代码来源:PptxExporter.java

示例9: testNull

import java.util.Base64; //导入方法依赖的package包/类
private static void testNull(Base64.Decoder dec) {
    checkNull(() -> dec.decode(ba_null));
    checkNull(() -> dec.decode(str_null));
    checkNull(() -> dec.decode(ba_null, new byte[10]));
    checkNull(() -> dec.decode(new byte[10], ba_null));
    checkNull(() -> dec.decode(bb_null));
    checkNull(() -> dec.wrap((InputStream)null));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:9,代码来源:TestBase64.java

示例10: testIOE

import java.util.Base64; //导入方法依赖的package包/类
private static void testIOE(Base64.Decoder dec, byte[] decoded) throws Throwable {
    ByteArrayInputStream bais = new ByteArrayInputStream(decoded);
    InputStream is = dec.wrap(bais);
    is.read(new byte[10]);
    is.close();
    checkIOE(() -> is.read());
    checkIOE(() -> is.read(new byte[] {10}));
    checkIOE(() -> is.read(new byte[] {10}, 1, 4));
    checkIOE(() -> is.available());
    checkIOE(() -> is.skip(20));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:12,代码来源:TestBase64.java

示例11: decrypt

import java.util.Base64; //导入方法依赖的package包/类
/**
 * Decrypts password using secret key
 * @param encryptedText
 * @return
 * @throws Exception
 */
public String decrypt(String encryptedText) throws Exception
{
    logger.debug("Decryption algo running");
    Cipher cipher = Cipher.getInstance(ALGO + "/" + MODE + "/" + PADDING);
    cipher.init(Cipher.DECRYPT_MODE, key);

    Base64.Decoder decoder = Base64.getDecoder();
    byte[] decryptedByte = cipher.doFinal(decoder.decode(encryptedText));

    String decryptedText = new String(decryptedByte);
    logger.debug("Decryption algo executed");
    return decryptedText;
}
 
开发者ID:Vedang18,项目名称:ProBOT,代码行数:20,代码来源:PasswordCoder.java

示例12: testDecode

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

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

示例13: testDecoderKeepsAbstinence

import java.util.Base64; //导入方法依赖的package包/类
private static void testDecoderKeepsAbstinence(Base64.Decoder dec)
        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[3];
    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);

            String input = "AAAAAAAAAAAAAAAAAAAAAA";
            ByteArrayInputStream bais =
                    new ByteArrayInputStream(input.getBytes("Latin1"));
            try (InputStream is = dec.wrap(bais)) {
                is.read(buf, off, len);
                throw new RuntimeException("Expected IOOBEx was not thrown");
            } catch (IndexOutOfBoundsException expected) {
            }
            if (bais.available() != input.length())
                throw new RuntimeException("No input should be consumed, "
                        + "but consumed " + (input.length() - bais.available())
                        + " bytes");
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:33,代码来源:TestBase64.java

示例14: decrypt

import java.util.Base64; //导入方法依赖的package包/类
public String decrypt(String encryptedText, String encryptedKey)throws Exception 
{
       Base64.Decoder decoder = Base64.getDecoder();
       setSecretKey(new SecretKeySpec(decoder.decode(encryptedKey),0,decoder.decode(encryptedKey).length,"AES"));
       byte [] encryptedTextByte = decoder.decode(encryptedText);
       cpr.init(Cipher.DECRYPT_MODE, sk);
       byte [] decryptedByte = cpr.doFinal(encryptedTextByte);
       String decryptedText = new String(decryptedByte);
       return (decryptedText);
}
 
开发者ID:Tejas07PSK,项目名称:maven_EWorld_OpenShift,代码行数:11,代码来源:AES.java

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


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