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


Java Base64.encode方法代碼示例

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


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

示例1: testEncryptRijndael

import org.bouncycastle.util.encoders.Base64; //導入方法依賴的package包/類
public String testEncryptRijndael(String value,String key) throws DataLengthException, IllegalStateException, InvalidCipherTextException {
    BlockCipher engine = new RijndaelEngine(256);
    BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(engine), new ZeroBytePadding());

    byte[] keyBytes = key.getBytes();
    cipher.init(true, new KeyParameter(keyBytes));

    byte[] input = value.getBytes();
    byte[] cipherText = new byte[cipher.getOutputSize(input.length)];

    int cipherLength = cipher.processBytes(input, 0, input.length, cipherText, 0);
    cipher.doFinal(cipherText, cipherLength);

    String result = new String(Base64.encode(cipherText));
    //Log.e("testEncryptRijndael : " , result);
    return  result;
}
 
開發者ID:David-Hackro,項目名稱:ExamplesAndroid,代碼行數:18,代碼來源:Metodos.java

示例2: writeEncoded

import org.bouncycastle.util.encoders.Base64; //導入方法依賴的package包/類
private void writeEncoded(byte[] bytes)
    throws IOException
{
    bytes = Base64.encode(bytes);

    for (int i = 0; i < bytes.length; i += buf.length)
    {
        int index = 0;

        while (index != buf.length)
        {
            if ((i + index) >= bytes.length)
            {
                break;
            }
            buf[index] = (char)bytes[i + index];
            index++;
        }
        this.write(buf, 0, index);
        this.newLine();
    }
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:23,代碼來源:PemWriter.java

示例3: EncryptMsg

import org.bouncycastle.util.encoders.Base64; //導入方法依賴的package包/類
/**
 * 加密
 * @param strMsg 明文
 * @return 加密後的byte數組(base64)
 * @since  1.0
 */
public byte[] EncryptMsg(String strMsg) {
    try {
        byte[] pInData = strMsg.getBytes("utf8");
        int nInLen = pInData.length;
        int nRemain = nInLen % 16;
        int nBlocks = (nInLen + 15) / 16;

        if (nRemain > 12 || nRemain == 0) {
            nBlocks += 1;
        }
        int nEncryptLen = nBlocks * 16;

        byte[] pData = Arrays.copyOf(pInData, nEncryptLen);

        byte[] lenbytes = CommonUtils.intToBytes(nInLen);

        for (int i = 0; i < 4; i++) {
            pData[nEncryptLen + i - 4] = lenbytes[i];
        }
        byte[] encrypted = AESUtils.encrypt(pData);
        return Base64.encode(encrypted);
    } catch (UnsupportedEncodingException e) {
        return new byte[]{};
    }
}
 
開發者ID:ccfish86,項目名稱:sctalk,代碼行數:32,代碼來源:SecurityUtils.java

示例4: encrypt

import org.bouncycastle.util.encoders.Base64; //導入方法依賴的package包/類
public String encrypt( String unencryptedString ) throws EncryptionException
{
    if ( unencryptedString == null || unencryptedString.trim().length() == 0 )
        throw new IllegalArgumentException(
        "unencrypted string was null or empty" );
    
    try
    {
        SecretKey key = keyFactory.generateSecret( keySpec );
        cipher.init( Cipher.ENCRYPT_MODE, key );
        byte[] cleartext = unencryptedString.getBytes( UNICODE_FORMAT );
        byte[] ciphertext = cipher.doFinal( cleartext );
        
        return new String( Base64.encode( ciphertext ));
    }
    catch (Exception e)
    {
        throw new EncryptionException( e );
    }
}
 
開發者ID:thangbn,項目名稱:Direct-File-Downloader,代碼行數:21,代碼來源:StringEncrypter.java

示例5: writeEncoded

import org.bouncycastle.util.encoders.Base64; //導入方法依賴的package包/類
private void writeEncoded(byte[] bytes) 
    throws IOException
{
    char[]  buf = new char[64];
    
    bytes = Base64.encode(bytes);
    
    for (int i = 0; i < bytes.length; i += buf.length)
    {
        int index = 0;
        
        while (index != buf.length)
        {
            if ((i + index) >= bytes.length)
            {
                break;
            }
            buf[index] = (char)bytes[i + index];
            index++;
        }
        this.write(buf, 0, index);
        this.newLine();
    }
}
 
開發者ID:thangbn,項目名稱:Direct-File-Downloader,代碼行數:25,代碼來源:PEMWriter.java

示例6: encodeToJSONObject

import org.bouncycastle.util.encoders.Base64; //導入方法依賴的package包/類
/**
 * encodes a map into a JSONObject.
 * <P>
 * It's recommended that you use {@link #encodeToJSON(Map)} instead
 * 
 * @param map
 * @return
 *
 * @since 3.0.1.5
 */
public static Map encodeToJSONObject(Map map) {
    Map newMap = new JSONObject();

    for (Iterator iter = map.keySet().iterator(); iter.hasNext();) {
        String key = (String) iter.next();
        Object value = map.get(key);

        if (value instanceof byte[]) {
            key += ".B64";
            value = Base64.encode((byte[]) value);
        }

        value = coerce(value);

        newMap.put(key, value);
    }
    return newMap;
}
 
開發者ID:thangbn,項目名稱:Direct-File-Downloader,代碼行數:29,代碼來源:JSONUtils.java

示例7: dumpBase64

import org.bouncycastle.util.encoders.Base64; //導入方法依賴的package包/類
public static String dumpBase64(
    byte[] data)
{
    StringBuffer buf = new StringBuffer();

    data = Base64.encode(data);

    for (int i = 0; i < data.length; i += 64)
    {
        if (i + 64 < data.length)
        {
            buf.append(new String(data, i, 64));
        }
        else
        {
            buf.append(new String(data, i, data.length - i));
        }
        buf.append('\n');
    }

    return buf.toString();
}
 
開發者ID:ttt43ttt,項目名稱:gwt-crypto,代碼行數:23,代碼來源:CMSTestUtil.java

示例8: toPublicOpenSSHFormat

import org.bouncycastle.util.encoders.Base64; //導入方法依賴的package包/類
public static String toPublicOpenSSHFormat(RSAPublicKey rsaPublicKey) {
    ByteArrayOutputStream byteOs = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(byteOs);
    try {
        dos.writeInt("ssh-rsa".getBytes().length);
        dos.write("ssh-rsa".getBytes());

        dos.writeInt(rsaPublicKey.getPublicExponent().toByteArray().length);
        dos.write(rsaPublicKey.getPublicExponent().toByteArray());

        dos.writeInt(rsaPublicKey.getModulus().toByteArray().length);
        dos.write(rsaPublicKey.getModulus().toByteArray());

        String publicKeyEncoded = new String(Base64.encode(byteOs.toByteArray()));
        return "ssh-rsa " + publicKeyEncoded;
    } catch (IOException e) {
        throw new RuntimeException("Failed to encode public key to OpenSSH format", e);
    }
}
 
開發者ID:vmware,項目名稱:photon-model,代碼行數:20,代碼來源:KeyUtil.java

示例9: buildCRT

import org.bouncycastle.util.encoders.Base64; //導入方法依賴的package包/類
private static byte[] buildCRT(TBSCertificate tbs, AlgorithmIdentifier aid, byte[] sig) {
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(tbs);
    v.add(aid);
    v.add(new DERBitString(sig));

    byte [] crt = null;
    try {
        Certificate c = Certificate.getInstance(new DERSequence(v));
        crt = c.getEncoded();
        Base64.encode(crt, System.out);
        System.out.println("");
    } catch (Exception ex) {
        ex.printStackTrace(System.out);
        Assert.fail();
    }
    return crt;
}
 
開發者ID:mbrossard,項目名稱:cryptonit-applet,代碼行數:19,代碼來源:PivTest.java

示例10: createTBS

import org.bouncycastle.util.encoders.Base64; //導入方法依賴的package包/類
private static TBSCertificate createTBS(ByteArrayOutputStream bOut, SubjectPublicKeyInfo ski, AlgorithmIdentifier algo) throws IOException {
    TBSCertificate tbs = null;

    V1TBSCertificateGenerator tbsGen = new V1TBSCertificateGenerator();
    tbsGen.setSerialNumber(new ASN1Integer(0x1));
    tbsGen.setStartDate(new Time(new Date(100, 01, 01, 00, 00, 00)));
    tbsGen.setEndDate(new Time(new Date(130, 12, 31, 23, 59, 59)));
    tbsGen.setIssuer(new X500Name("CN=Cryptonit"));
    tbsGen.setSubject(new X500Name("CN=Cryptonit"));
    tbsGen.setSignature(algo);
    tbsGen.setSubjectPublicKeyInfo(ski);
    tbs = tbsGen.generateTBSCertificate();

    ASN1OutputStream aOut = new ASN1OutputStream(bOut);
    aOut.writeObject(tbs);
    System.out.println("Build TBS");
    System.out.println(toHex(bOut.toByteArray()));
    Base64.encode(bOut.toByteArray(), System.out);
    System.out.println();

    return tbs;
}
 
開發者ID:mbrossard,項目名稱:cryptonit-applet,代碼行數:23,代碼來源:PivTest.java

示例11: hashSignedAttribADRB10

import org.bouncycastle.util.encoders.Base64; //導入方法依賴的package包/類
public String hashSignedAttribADRB10(String origHashB64, Date signingTime,
        String x509B64) throws Exception {

    logger.debug("hashSignedAttribSha1: " + "\norigHashB64 (" + origHashB64
            + ")" + "\nsigningTime(" + signingTime + ")" + "\nx509B64("
            + x509B64 + ")");

    try {
        byte[] origHash = Base64.decode(origHashB64);
        byte[] x509 = Base64.decode(x509B64);
        X509Certificate cert = loadCertFromB64(x509);

        byte[] ret = ccServ.hashSignedAttribSha1(origHash, signingTime,
                cert);

        return new String(  Base64.encode(ret) );
    } catch (Exception e) {
        logger.error("ERRO: ", e);
        throw e;
    }

}
 
開發者ID:bluecrystalsign,項目名稱:signer-source,代碼行數:23,代碼來源:IcpbrServiceImpl.java

示例12: hashSignedAttribADRB21

import org.bouncycastle.util.encoders.Base64; //導入方法依賴的package包/類
public String hashSignedAttribADRB21(String origHashB64, Date signingTime,
        String x509B64) throws Exception {
    logger.debug("hashSignedAttribSha256: " + "\norigHashB64 (" + origHashB64
            + ")" + "\nsigningTime(" + signingTime + ")" + "\nx509B64("
            + x509B64 + ")");
    try {
        byte[] origHash = Base64.decode(origHashB64);
        byte[] x509 = Base64.decode(x509B64);
        X509Certificate cert = loadCertFromB64(x509);

        byte[] ret = ccServ.hashSignedAttribSha256(origHash, signingTime,
                cert);

        return new String( Base64.encode(ret) );
    } catch (Exception e) {
        logger.error("ERRO: ", e);
        throw e;
    }
}
 
開發者ID:bluecrystalsign,項目名稱:signer-source,代碼行數:20,代碼來源:IcpbrServiceImpl.java

示例13: hashSignedAttribADRB21

import org.bouncycastle.util.encoders.Base64; //導入方法依賴的package包/類
public String hashSignedAttribADRB21(String origHashB64, Date signingTime, String x509B64) throws Exception {
    // logger.debug("hashSignedAttribSha256: " + "\norigHashB64 (" +
    // origHashB64
    // + ")" + "\nsigningTime(" + signingTime + ")" + "\nx509B64("
    // + x509B64 + ")");
    try {
        byte[] origHash = Base64.decode(origHashB64);
        byte[] x509 = Base64.decode(x509B64);
        X509Certificate cert = certServ.createFromB64(x509);

        byte[] ret = ccServ.hashSignedAttribSha256(origHash, signingTime, cert);

        return new String(Base64.encode(ret));
    } catch (Exception e) {
        // ;logger.error("ERRO: ", e);
        throw e;
    }
}
 
開發者ID:bluecrystalsign,項目名稱:signer-source,代碼行數:19,代碼來源:ServiceFacade.java

示例14: verifySignature

import org.bouncycastle.util.encoders.Base64; //導入方法依賴的package包/類
private boolean verifySignature(Boolean algSha256, String ret, String filename) throws Exception {
        
        MessageDigest hashSum = null;
        if(algSha256){
            hashSum = MessageDigest.getInstance("SHA-256");
            logger.debug("Validar assinatura SHA-256");

        } else {
            hashSum = MessageDigest.getInstance("SHA-1");
            logger.debug("Validar assinatura SHA-1");
        }
        hashSum.update(Convert.readFile(filename));
        byte[] digestResult = hashSum.digest();
        
//		Base64.Encoder encoder = Base64.getEncoder(); 
        String digestB64 = new String(Base64.encode(digestResult));
        return serv.validateSign(ret, digestB64, Convert.asXMLGregorianCalendar(new Date()), false);
    }
 
開發者ID:bluecrystalsign,項目名稱:signer-source,代碼行數:19,代碼來源:CreateEnvelope.java

示例15: validateSignWithStatus

import org.bouncycastle.util.encoders.Base64; //導入方法依賴的package包/類
private int validateSignWithStatus(Boolean algSha256, String ret, String filename) throws Exception {
        
        MessageDigest hashSum = null;
        if(algSha256){
            hashSum = MessageDigest.getInstance("SHA-256");
            logger.debug("Validar assinatura SHA-256");

        } else {
            hashSum = MessageDigest.getInstance("SHA-1");
            logger.debug("Validar assinatura SHA-1");
        }
        hashSum.update(Convert.readFile(filename));
        byte[] digestResult = hashSum.digest();
        
//		Base64.Encoder encoder = Base64.getEncoder(); 
        String digestB64 = new String(Base64.encode(digestResult));
        return serv.validateSignWithStatus(ret, digestB64, Convert.asXMLGregorianCalendar(new Date()), false);
    }
 
開發者ID:bluecrystalsign,項目名稱:signer-source,代碼行數:19,代碼來源:CreateEnvelope.java


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