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


Java Base64类代码示例

本文整理汇总了Java中net.iharder.Base64的典型用法代码示例。如果您正苦于以下问题:Java Base64类的具体用法?Java Base64怎么用?Java Base64使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: challenge

import net.iharder.Base64; //导入依赖的package包/类
@Override
public CharSequence challenge()
{
    try
    {
        String result = Base64.encodeBytes(new Digest(new Sha256(), mCodeVerifier).value(), Base64.URL_SAFE);
        // Note, the code challenge parameter doesn't support equals chars, so we have to remove any padding
        if (result.endsWith("=="))
        {
            return result.substring(0, result.length() - 2);
        }
        if (result.endsWith("="))
        {
            return result.substring(0, result.length() - 1);
        }
        return result;
    }
    catch (IOException e)
    {
        throw new RuntimeException("IOException while operating on strings");
    }
}
 
开发者ID:dmfs,项目名称:oauth2-essentials,代码行数:23,代码来源:S256CodeChallenge.java

示例2: deserialize

import net.iharder.Base64; //导入依赖的package包/类
@BotCommandHandler
private void deserialize(Message message, String content) throws IOException {
  outputChannel.set((TextChannel) message.getChannel());
  connectToFirstVoiceChannel(guild.getAudioManager());

  byte[] bytes = Base64.decode(content);

  MessageInput inputStream = new MessageInput(new ByteArrayInputStream(bytes));
  DecodedTrackHolder holder;

  while ((holder = manager.decodeTrack(inputStream)) != null) {
    if (holder.decodedTrack != null) {
      scheduler.addToQueue(holder.decodedTrack);
    }
  }
}
 
开发者ID:sedmelluq,项目名称:lavaplayer,代码行数:17,代码来源:MusicController.java

示例3: sign

import net.iharder.Base64; //导入依赖的package包/类
/**
 * 用私钥对指定信息进行签名,并返回电子签名.
 *
 * @param priKeyStr 私钥
 * @param plainText 待签名的字符串
 * @return 电子签名
 */
public static String sign(String priKeyStr, String plainText) {

  try {
    PrivateKey prikey = RsaUtil.getPrivateKey(Base64.decode(priKeyStr));

    // 用私钥对信息生成数字签名
    Signature signet = Signature.getInstance("MD5withRSA");
    signet.initSign(prikey);
    signet.update(plainText.getBytes());

    return Base64.encodeBytes(signet.sign());

  } catch (Exception e) {
    throw new BaseSecurityException("E-BASE-SECURITY-000001").initCause(e);
  }

}
 
开发者ID:ibankapp,项目名称:ibankapp-base,代码行数:25,代码来源:SignProvider.java

示例4: verify

import net.iharder.Base64; //导入依赖的package包/类
/**
 * 校验传入的plaintextbyte数组,与原加签的字符串验证运算是否验证通过.
 *
 * @param pubKeyBytes 公钥
 * @param plainText 待验证的字符串
 * @param signText 通过私钥数字签名后的密文(Base64编码)
 * @return true:验证通过 false:验证失败
 */
private static boolean verify(byte[] pubKeyBytes, String signText, String plainText) {

  try {
    // 取公钥匙对象
    PublicKey pubKey = RsaUtil.getPublicKey(pubKeyBytes);

    // 解密由base64编码的数字签名
    byte[] signed = Base64.decode(signText);
    Signature signatureChecker = Signature.getInstance("MD5withRSA");
    signatureChecker.initVerify(pubKey);
    signatureChecker.update(plainText.getBytes());

    // 验证签名是否正常
    return signatureChecker.verify(signed);
  } catch (Exception e) {
    throw new BaseSecurityException("E-BASE-SECURITY-000002").initCause(e);
  }
}
 
开发者ID:ibankapp,项目名称:ibankapp-base,代码行数:27,代码来源:SignProvider.java

示例5: encryptValue

import net.iharder.Base64; //导入依赖的package包/类
private static String encryptValue( final String value, final String key )
        throws ChaiOperationException
{
    try
    {
        if ( value == null || value.length() < 1 )
        {
            return "";
        }

        final SecretKey secretKey = makeKey( key );
        final Cipher cipher = Cipher.getInstance( "AES" );
        cipher.init( Cipher.ENCRYPT_MODE, secretKey, cipher.getParameters() );
        final byte[] encrypted = cipher.doFinal( value.getBytes() );
        return Base64.encodeBytes( encrypted, Base64.URL_SAFE | Base64.GZIP );
    }
    catch ( Exception e )
    {
        final String errorMsg = "unexpected error performing helpdesk answer crypt operation: " + e.getMessage();
        throw new ChaiOperationException( errorMsg, ChaiError.CHAI_INTERNAL_ERROR );
    }
}
 
开发者ID:ldapchai,项目名称:ldapchai,代码行数:23,代码来源:ChaiHelpdeskAnswer.java

示例6: decryptValue

import net.iharder.Base64; //导入依赖的package包/类
private static String decryptValue( final String value, final String key )
{
    try
    {
        if ( value == null || value.length() < 1 )
        {
            return "";
        }

        final SecretKey secretKey = makeKey( key );
        final byte[] decoded = Base64.decode( value, Base64.URL_SAFE | Base64.GZIP );
        final Cipher cipher = Cipher.getInstance( "AES" );
        cipher.init( Cipher.DECRYPT_MODE, secretKey );
        final byte[] decrypted = cipher.doFinal( decoded );
        return new String( decrypted );
    }
    catch ( Exception e )
    {
        final String errorMsg = "unexpected error performing helpdesk answer decrypt operation: " + e.getMessage();
        throw new IllegalArgumentException( errorMsg );
    }
}
 
开发者ID:ldapchai,项目名称:ldapchai,代码行数:23,代码来源:ChaiHelpdeskAnswer.java

示例7: signGMapRequest

import net.iharder.Base64; //导入依赖的package包/类
/**
 * Private Helper Method to Sign Requests.
 *
 * @param resource
 * @return  String
 * @throws java.security.NoSuchAlgorithmException
 * @throws java.security.InvalidKeyException
 * @throws java.io.UnsupportedEncodingException
 * @throws java.net.URISyntaxException
 * @throws java.io.IOException
 */
private String signGMapRequest(String resource) throws NoSuchAlgorithmException,
        InvalidKeyException, URISyntaxException, IOException {

    URL url = new URL(resource);
    log.warn("Signing URL Path:["+url.getPath()+"], URL Query:["+url.getQuery()+"]");
     // get an hmac_sha1 key from the raw key bytes
        SecretKeySpec signingKey = new SecretKeySpec(this.binaryClientSignature, SecurityConstants.HMAC_SHA1);
        // get an hmac_sha1 Mac instance and initialize with the signing key
        Mac mac = Mac.getInstance(SecurityConstants.HMAC_SHA1);
        mac.init(signingKey);
        // compute the hmac on input data bytes
        byte[] sigBytes = mac.doFinal((url.getPath() + "?" + url.getQuery()).getBytes());

    // base 64 encode the binary signature
    String signature = Base64.encodeBytes(sigBytes);
    signature = signature.replace('+', '-');
    signature = signature.replace('/', '_');
    return resource + "&signature=" + signature;
}
 
开发者ID:jaschenk,项目名称:jeffaschenk-commons,代码行数:31,代码来源:GeoCodingServiceProviderImpl.java

示例8: doGet

import net.iharder.Base64; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
  String ctlExportKeyBase64 = URLDecoder
      .decode(request.getParameter(CTL_EXPORT_KEY_PARAMETER), "UTF-8");
  try {
    CtlSchemaExportKey key = (CtlSchemaExportKey) Base64
        .decodeToObject(ctlExportKeyBase64, Base64.URL_SAFE, null);
    FileData ctlExportData = cacheService.getExportedCtlSchema(key);
    ServletUtils.prepareDisposition(request, response, ctlExportData.getFileName());
    response.setContentType(ctlExportData.getContentType());
    response.setContentLength(ctlExportData.getFileData().length);
    response.setBufferSize(BUFFER);
    response.getOutputStream().write(ctlExportData.getFileData());
    response.flushBuffer();
  } catch (Exception ex) {
    LOG.error("Unexpected error in CtlExportServlet.doGet: ", ex);
    response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to get file: "
        + ex.getMessage());
  }
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:22,代码来源:CtlExportServlet.java

示例9: doGet

import net.iharder.Base64; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
  String recordKeyBase64 = URLDecoder.decode(request.getParameter(RECORD_KEY_PARAMETER), "UTF-8");
  try {
    RecordKey key = (RecordKey) Base64.decodeToObject(recordKeyBase64, Base64.URL_SAFE, null);
    FileData recordLibrary = cacheService.getRecordData(key);
    ServletUtils.prepareDisposition(request, response, recordLibrary.getFileName());
    response.setContentLength(recordLibrary.getFileData().length);
    response.setBufferSize(BUFFER);
    response.getOutputStream().write(recordLibrary.getFileData());
    response.flushBuffer();
  } catch (Exception ex) {
    LOG.error("Unexpected error in RecordLibraryServlet.doGet: ", ex);
    response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to get file: "
        + ex.getMessage());
  }
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:19,代码来源:RecordServlet.java

示例10: doGet

import net.iharder.Base64; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
  String sdkKeyBase64 = URLDecoder.decode(request.getParameter(SDK_KEY_PARAMETER), "UTF-8");
  try {
    CacheService.SdkKey key = (CacheService.SdkKey) Base64
        .decodeToObject(sdkKeyBase64, Base64.URL_SAFE, null);
    FileData sdkFile = cacheService.getSdk(key);
    response.setContentType(sdkFile.getContentType());
    ServletUtils.prepareDisposition(request, response, sdkFile.getFileName());
    response.setContentLength(sdkFile.getFileData().length);
    response.setBufferSize(BUFFER);
    response.getOutputStream().write(sdkFile.getFileData());
    response.flushBuffer();
  } catch (Exception ex) {
    LOG.error("Unexpected error in SdkServlet.doGet: ", ex);
    response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to get Sdk file: "
        + ex.getMessage());
  }
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:21,代码来源:SdkServlet.java

示例11: prepareCtlSchemaExport

import net.iharder.Base64; //导入依赖的package包/类
@Override
public String prepareCtlSchemaExport(String ctlSchemaId,
                                     CTLSchemaExportMethod method)
    throws KaaAdminServiceException {
  checkAuthority(KaaAuthorityDto.values());
  try {
    CTLSchemaDto schemaFound = controlService.getCtlSchemaById(ctlSchemaId);
    Utils.checkNotNull(schemaFound);
    checkCtlSchemaReadScope(
        schemaFound.getMetaInfo().getTenantId(), schemaFound.getMetaInfo().getApplicationId());
    CtlSchemaExportKey key = new CtlSchemaExportKey(ctlSchemaId, method);
    return Base64.encodeObject(key, Base64.URL_SAFE);
  } catch (Exception ex) {
    throw Utils.handleException(ex);
  }
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:17,代码来源:CtlServiceImpl.java

示例12: sendUnicastNotification

import net.iharder.Base64; //导入依赖的package包/类
@Override
public EndpointNotificationDto sendUnicastNotification(NotificationDto notification,
                                                       String clientKeyHash,
                                                       byte[] body)
    throws KaaAdminServiceException {
  checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER);
  try {
    checkExpiredDate(notification);
    notification.setBody(body);
    checkApplicationId(notification.getApplicationId());
    TopicDto topic = controlService.getTopic(notification.getTopicId());
    Utils.checkNotNull(topic);
    checkApplicationId(topic.getApplicationId());
    EndpointNotificationDto unicastNotification = new EndpointNotificationDto();
    unicastNotification.setEndpointKeyHash(
        Base64.decode(clientKeyHash.getBytes(Charsets.UTF_8)));
    unicastNotification.setNotificationDto(notification);
    return controlService.editUnicastNotification(unicastNotification);
  } catch (Exception ex) {
    throw Utils.handleException(ex);
  }
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:23,代码来源:NotificationServiceImpl.java

示例13: testCDataNodes

import net.iharder.Base64; //导入依赖的package包/类
public void testCDataNodes() throws Exception {
    String text = "Text data -- left as it is";
    String textForBytes = "Byte data is automatically base64-encoded";
    String textEncoded = Base64.encodeBytes(textForBytes.getBytes("UTF-8"));

    BaseXMLBuilder builder = XMLBuilder_create("TestCDataNodes")
        .elem("CDataTextElem")
            .cdata(text)
            .up()
        .elem("CDataBytesElem")
            .cdata(textForBytes.getBytes("UTF-8"));

    Node cdataTextNode = builder.xpathFind("//CDataTextElem")
        .getElement().getChildNodes().item(0);
    assertEquals(Node.CDATA_SECTION_NODE, cdataTextNode.getNodeType());
    assertEquals(text, cdataTextNode.getNodeValue());

    Node cdataBytesNode = builder.xpathFind("//CDataBytesElem")
        .getElement().getChildNodes().item(0);
    assertEquals(Node.CDATA_SECTION_NODE, cdataBytesNode.getNodeType());
    assertEquals(textEncoded, cdataBytesNode.getNodeValue());
    String base64Decoded = new String(Base64.decode(cdataBytesNode.getNodeValue()));
    assertEquals(textForBytes, base64Decoded);
}
 
开发者ID:jmurty,项目名称:java-xmlbuilder,代码行数:25,代码来源:BaseXMLBuilderTests.java

示例14: unserialize

import net.iharder.Base64; //导入依赖的package包/类
public static EntityNBT unserialize(String serializedData) {
	try {
		NBTTagCompound data = NBTTagCompound.unserialize(Base64.decode(serializedData));

		// Backward compatibility with pre-1.9.
		// On 1.9 the entities are stacked for bottom to top.
		// This conversion needs to happen before instantiating any class, we cannot use onUnserialize.
		while (data.hasKey("Riding")) {
			NBTTagCompound riding = data.getCompound("Riding");
			data.remove("Riding");
			riding.setList("Passengers", new NBTTagList(data));
			data = riding;
		}

		EntityNBT entityNBT = fromEntityData(data);
		entityNBT.onUnserialize();
		return entityNBT;
	} catch (Throwable e) {
		throw new RuntimeException("Error unserializing EntityNBT.", e);
	}
}
 
开发者ID:goncalomb,项目名称:NBTEditor,代码行数:22,代码来源:EntityNBTBase.java

示例15: parse

import net.iharder.Base64; //导入依赖的package包/类
public static Base64Value parse(String value) throws PersistenceException {
    try {
        return new Base64Value(Base64.decode(value));
    } catch (IOException e) {
        throw new PersistenceException("Cannot Base64-decode: " + value);
    }
}
 
开发者ID:erickok,项目名称:retrofit-xmlrpc,代码行数:8,代码来源:Base64Value.java


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