当前位置: 首页>>代码示例>>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;未经允许,请勿转载。