本文整理汇总了Java中net.iharder.Base64.encodeBytes方法的典型用法代码示例。如果您正苦于以下问题:Java Base64.encodeBytes方法的具体用法?Java Base64.encodeBytes怎么用?Java Base64.encodeBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.iharder.Base64
的用法示例。
在下文中一共展示了Base64.encodeBytes方法的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: 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);
}
}
示例3: 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 );
}
}
示例4: 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;
}
示例5: 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);
}
示例6: createKey
import net.iharder.Base64; //导入方法依赖的package包/类
public static String createKey() {
final long now = currentTimeMillis();
final ByteBuffer buffer = ByteBuffer.wrap(new byte[8 + 1 + 8]);
buffer.putLong(now);
buffer.put(RANDOMNESS_BYTE);
buffer.putLong(getRandomPart(now));
try {
return Base64.encodeBytes(buffer.array(), 2, 15, Base64.ORDERED);
} catch (final IOException e) {
throw new SyndesisServerException(e);
}
}
示例7: tokenAuthHeader
import net.iharder.Base64; //导入方法依赖的package包/类
public String tokenAuthHeader() {
if (clientSecret != null) {
final String clientAndSecret = clientId + ":" + clientSecret;
final String encoded = Base64.encodeBytes(clientAndSecret.getBytes());
return "Basic " + encoded;
} else {
return "Client-ID " + clientId;
}
}
示例8: test_thatCorrectAuthHeaderGetsAdded_andOtherHeaderIsKept
import net.iharder.Base64; //导入方法依赖的package包/类
@Test
public void test_thatCorrectAuthHeaderGetsAdded_andOtherHeaderIsKept() throws Exception
{
// ARRANGE
Headers original = EmptyHeaders.INSTANCE.withHeader(HttpHeaders.CONTENT_LENGTH.entity(45));
BasicAuthHeaderDecoration decoration = new BasicAuthHeaderDecoration("user_name", "pw");
// ACT
Headers result = decoration.decorated(original);
// ASSERT
String expectedHeader = "Basic " + Base64.encodeBytes("user_name:pw".getBytes("UTF-8"));
assertEquals(expectedHeader, result.header(AUTHORIZATION_HEADER_TYPE).value());
assertTrue(result.contains(HttpHeaders.CONTENT_LENGTH));
}
示例9: test_thatExistingAuthHeaderIsOverridden
import net.iharder.Base64; //导入方法依赖的package包/类
@Test
public void test_thatExistingAuthHeaderIsOverridden() throws Exception
{
// ARRANGE
Headers original = EmptyHeaders.INSTANCE.withHeader(AUTHORIZATION_HEADER_TYPE.entity("dummy auth header value"));
BasicAuthHeaderDecoration decoration = new BasicAuthHeaderDecoration("user_name", "pw");
// ACT
Headers result = decoration.decorated(original);
// ASSERT
String expectedHeader = "Basic " + Base64.encodeBytes("user_name:pw".getBytes("UTF-8"));
assertEquals(expectedHeader, result.header(AUTHORIZATION_HEADER_TYPE).value());
}
示例10: performMasterLogin
import net.iharder.Base64; //导入方法依赖的package包/类
public Response performMasterLogin(String username,
String password,
String androidId,
String service,
String deviceCountry,
String operatorCountry,
String lang,
String sdkVersion) throws IOException {
byte[] signature = cipherUtil
.createSignature(
username,
password,
config.getModulus(),
config.getExponent()
);
String b64Signature = Base64.encodeBytes(signature, URL_SAFE);
FormBody formBody = new FormBody.Builder()
.add("accountType", "HOSTED_OR_GOOGLE")
.add("Email", username)
.add("has_permission", "1")
.add("add_account", "1")
.add("EncryptedPasswd", b64Signature)
.add("service", service)
.add("source", "android")
.add("androidId", androidId)
.add("device_country", deviceCountry)
.add("operatorCountry", operatorCountry)
.add("lang", lang)
.add("sdk_version", sdkVersion)
.build();
Request request = new Request.Builder()
.url("https://android.clients.google.com/auth")
.post(formBody)
.header("User-Agent", config.getUserAgent())
.build();
return httpClient.newCall(request).execute();
}
示例11: encrypt
import net.iharder.Base64; //导入方法依赖的package包/类
/**
* 加密.
*
* @param keyType 密钥类型
* @param skey 密钥字符串
* @param clearText 要加密的明文
* @param charset 使用的字符集
* @return 加密后的密文字符串
*/
public static String encrypt(KeyType keyType, String skey, String clearText, String charset) {
byte[] clearBytes;
try {
clearBytes = clearText.getBytes(charset);
} catch (UnsupportedEncodingException e) {
throw new BaseSecurityException("E-BASE-SECURITY-000010").initCause(e);
}
return Base64.encodeBytes(encrypt(keyType, skey, clearBytes));
}
示例12: doHash
import net.iharder.Base64; //导入方法依赖的package包/类
static String doHash(
final String input,
final int hashCount,
final FormatType formatType,
final VERSION version
)
throws IllegalStateException
{
final String algorithm = SUPPORTED_FORMATS.get( formatType );
final MessageDigest md;
try
{
md = MessageDigest.getInstance( algorithm );
}
catch ( NoSuchAlgorithmException e )
{
throw new IllegalStateException( "unable to load " + algorithm + " message digest algorithm: " + e.getMessage() );
}
byte[] hashedBytes = input.getBytes();
switch ( version )
{
case A:
hashedBytes = md.digest( hashedBytes );
return Base64.encodeBytes( hashedBytes );
case B:
for ( int i = 0; i < hashCount; i++ )
{
hashedBytes = md.digest( hashedBytes );
}
return Base64.encodeBytes( hashedBytes );
default:
throw new IllegalStateException( "unexpected version enum in hash method" );
}
}
示例13: readGUID
import net.iharder.Base64; //导入方法依赖的package包/类
public String readGUID()
throws ChaiOperationException, ChaiUnavailableException
{
final byte[][] guidValues = this.readMultiByteAttribute( "guid" );
if ( guidValues == null || guidValues.length < 1 )
{
return null;
}
final byte[] guidValue = guidValues[0];
return Base64.encodeBytes( guidValue );
}
示例14: call
import net.iharder.Base64; //导入方法依赖的package包/类
@Override
public StringValue call(XPathContext context, Sequence[] arguments) throws XPathException {
try {
String str = ((StringValue) arguments[0].head()).getStringValue();
return new StringValue("Hello World: " + Base64.encodeBytes(str.getBytes("UTF-8")));
} catch (Exception e) {
throw new XPathException("Could not base64 encode string", e);
}
}
示例15: onOpen
import net.iharder.Base64; //导入方法依赖的package包/类
public static void onOpen(AsynchronousSocketChannel asynchronousSocketChannel) throws InterruptedException, ExecutionException, TimeoutException, NoSuchAlgorithmException {
String WebSocketsMagicString = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
Properties properties = new Properties();
StringBuilder sb = new StringBuilder();
while (inputBuffer.hasRemaining()) {
sb.append((char) (inputBuffer.get() & 0xff));
}
String[] lines = sb.toString().split("\\n");
for (String line : lines) {
String[] keyVal = line.split(":");
if (keyVal.length == 2) {
properties.put(keyVal[0].trim(), keyVal[1].trim());
}
}
String message
= "HTTP/1.1 101 Switching Protocols\r\n"
+ "Connection: Upgrade\r\n"
+ "Sec-WebSocket-Accept: " + Base64.encodeBytes(MessageDigest.getInstance("SHA1").digest((properties.getProperty("Sec-WebSocket-Key") + WebSocketsMagicString).getBytes())) + "\r\n"
+ "Upgrade: websocket\r\n"
+ "\r\n";
outputBuffer = ByteBuffer.allocate(message.getBytes().length);
outputBuffer.put(message.getBytes());
outputBuffer.flip();
while (outputBuffer.hasRemaining()) {
asynchronousSocketChannel.write(outputBuffer);
}
outputBuffer = encodeUnmaskedFrame(1, "Connection Established");
outputBuffer.flip();
outputBuffer.rewind();
while (outputBuffer.hasRemaining()) {
asynchronousSocketChannel.write(outputBuffer);
}
}