本文整理汇总了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");
}
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
}
示例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 );
}
}
示例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 );
}
}
示例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;
}
示例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());
}
}
示例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());
}
}
示例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());
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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);
}
}