本文整理匯總了Java中org.apache.commons.codec.binary.StringUtils.getBytesUtf8方法的典型用法代碼示例。如果您正苦於以下問題:Java StringUtils.getBytesUtf8方法的具體用法?Java StringUtils.getBytesUtf8怎麽用?Java StringUtils.getBytesUtf8使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.codec.binary.StringUtils
的用法示例。
在下文中一共展示了StringUtils.getBytesUtf8方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: desEncode
import org.apache.commons.codec.binary.StringUtils; //導入方法依賴的package包/類
/**
* DES算法,加密
*
* @param data 待加密字符串
* @param key 加密私鑰,長度不能夠小於8位
* @return 加密後字符串
* @throws Exception
*/
public static String desEncode(String key, String data) {
if (data == null)
return null;
try {
DESKeySpec dks = new DESKeySpec(StringUtils.getBytesUtf8(key));
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
//key的長度不能夠小於8位字節
Key secretKey = keyFactory.generateSecret(dks);
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
IvParameterSpec iv = new IvParameterSpec(StringUtils.getBytesUtf8("12345678"));
AlgorithmParameterSpec paramSpec = iv;
cipher.init(Cipher.ENCRYPT_MODE, secretKey, paramSpec);
byte[] bytes = cipher.doFinal(StringUtils.getBytesUtf8(data));
return Hex.encodeHexString(bytes);
} catch (Exception e) {
throw new RuntimeException("des加密失敗", e);
}
}
示例2: desDecode
import org.apache.commons.codec.binary.StringUtils; //導入方法依賴的package包/類
/**
* DES算法,解密
*
* @param data 待解密字符串
* @param key 解密私鑰,長度不能夠小於8位
* @return 解密後的字符串
* @throws Exception 異常
*/
public static String desDecode(String key, String data) {
if (data == null)
return null;
try {
DESKeySpec dks = new DESKeySpec(StringUtils.getBytesUtf8(key));
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
//key的長度不能夠小於8位字節
Key secretKey = keyFactory.generateSecret(dks);
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
IvParameterSpec iv = new IvParameterSpec(StringUtils.getBytesUtf8("12345678"));
AlgorithmParameterSpec paramSpec = iv;
cipher.init(Cipher.DECRYPT_MODE, secretKey, paramSpec);
byte[] bytes = Hex.decodeHex(data.toCharArray());
return StringUtils.newStringUtf8(cipher.doFinal(bytes));
} catch (Exception e) {
throw new RuntimeException("des解密失敗", e);
}
}
示例3: deflate
import org.apache.commons.codec.binary.StringUtils; //導入方法依賴的package包/類
public static byte[] deflate(final String data) throws SCSException {
final byte[] toDeflate = StringUtils.getBytesUtf8(data);
final Deflater deflater = new Deflater();
final byte[] tmp = new byte[4096];
deflater.setInput(toDeflate);
deflater.finish();
final int outSize = deflater.deflate(tmp);
if(!deflater.finished()) {
throw new SCSException("Can not deflate session data. Data is too large.");
}
deflater.end();
final byte[] out = new byte[outSize];
System.arraycopy(tmp, 0, out, 0, outSize);
return out;
}
示例4: createHmac
import org.apache.commons.codec.binary.StringUtils; //導入方法依賴的package包/類
@Override
public byte[] createHmac(String tid, String msg) {
final byte[] result = new byte[mac.getMacSize()];
final byte[] in = StringUtils.getBytesUtf8(msg);
mac.update(in, 0, in.length);
mac.doFinal(result, 0);
return result;
}
示例5: testDecodeNibbleHex
import org.apache.commons.codec.binary.StringUtils; //導入方法依賴的package包/類
@Test
public void testDecodeNibbleHex() throws DecoderException {
byte[] bytes = StringUtils
.getBytesUtf8("F0F1F0F0723C440188E18008F1F9F5F4F0F5F6F2F0F0F0F0F0F0F0F0F0F0F0F1F4F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F5F0F5F0F1F2F0F1F3F0F3F0F9F5F8F9F2F7F8F1F3F0F3F0F9F0F1F2F0F1F5F1F1F5F4F1F1F8F1F2F0F6F0F1F3F4F0F1F0F6F2F0F0F3F5F0F0F1F2F0F1F4F5F4F9F3F5F482F0F0F0F0F0F0F1D9C5E3D382F0F0F0F0F0F0F1404040C3C3C240E3F140E28899A340D581948540404040404040C3C3C240E3F140E28899A340D340D7C1D5F0F6F0E3F6F1F0F5F0F0F0F0F1F9F2F0F35C5C5CF4F2F0F7F0F1F0F3F2F1F2F4F3F2F891C982A884F6E38581889492C1C2C5C1C1C1C699D894A8E7A694F07EF9F7F8F0F2F1F1F0F2F5F1F0F0F0F0F6F0F0F0F5F9F1D7C1D5F1F2");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < bytes.length; i++) {
}
Hex hexer = new Hex();
byte[] bytesDec = hexer.decode(bytes);
for (int i = 0; i < bytesDec.length; i++) {
sb.append(String.format("%01X", bytesDec[i]));
}
}
示例6: sendPostRequest
import org.apache.commons.codec.binary.StringUtils; //導入方法依賴的package包/類
/**
* @param requestURL Ссылка на получателя
* @param data POST-данные
* @return Возвращает строку содержащую ответ сервера. Если отправить запрос
* или получить ответ не удалось, возвращается строка BAD_CONNECTION
* @throws IOException
*/
public static final String sendPostRequest(URL requestURL, String data) throws IOException {
byte[] bytes = StringUtils.getBytesUtf8(data);
HttpURLConnection conn = (HttpURLConnection) requestURL.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Content-Length", Integer.toString(bytes.length));
conn.setUseCaches(false);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.connect();
OutputStream wr = conn.getOutputStream();
wr.write(bytes);
wr.flush();
wr.close();
StringBuffer s = new StringBuffer();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
String line;
while ((line = reader.readLine()) != null) {
s.append(line);
}
reader.close();
return s.toString();
}
示例7: setKey
import org.apache.commons.codec.binary.StringUtils; //導入方法依賴的package包/類
public void setKey(String k) {
key = StringUtils.getBytesUtf8(k);
}
示例8: appendPredicate
import org.apache.commons.codec.binary.StringUtils; //導入方法依賴的package包/類
private static void appendPredicate(final Statement statement, final Text keyText) {
final Value statementValue = new Value(StringUtils.getBytesUtf8(StatementSerializer.writePredicate(statement)));
final byte[] hashOfValue = uniqueFromValueForKey(statementValue);
appendBytes(HASH_PREFIX, keyText); // prefix the hash with a zero byte.
appendBytes(hashOfValue, keyText);
}
示例9: appendSubjectPredicate
import org.apache.commons.codec.binary.StringUtils; //導入方法依賴的package包/類
private static void appendSubjectPredicate(final Statement statement, final Text keyText) {
final Value statementValue = new Value(StringUtils.getBytesUtf8(StatementSerializer.writeSubjectPredicate(statement)));
final byte[] hashOfValue = uniqueFromValueForKey(statementValue);
appendBytes(HASH_PREFIX, keyText); // prefix the hash with a zero byte.
appendBytes(hashOfValue, keyText);
}
示例10: getAsKeyBytes
import org.apache.commons.codec.binary.StringUtils; //導入方法依賴的package包/類
@Override
public byte[] getAsKeyBytes() {
return StringUtils.getBytesUtf8(getAsKeyString());
}
示例11: getBytesUtf8
import org.apache.commons.codec.binary.StringUtils; //導入方法依賴的package包/類
private static byte[] getBytesUtf8(String data)
/* 28: */ {
/* 29: 69 */ return StringUtils.getBytesUtf8(data);
/* 30: */ }
示例12: createHmac
import org.apache.commons.codec.binary.StringUtils; //導入方法依賴的package包/類
@Override
public byte[] createHmac(String tid, String msg) {
final byte[] in = StringUtils.getBytesUtf8(msg);
return mac.get().doFinal(in);
}
示例13: getBytesUtf8
import org.apache.commons.codec.binary.StringUtils; //導入方法依賴的package包/類
private static byte[] getBytesUtf8(String paramString)
{
return StringUtils.getBytesUtf8(paramString);
}
示例14: testBase64Encoder
import org.apache.commons.codec.binary.StringUtils; //導入方法依賴的package包/類
@Test
public void testBase64Encoder() {
final byte[] value = StringUtils.getBytesUtf8("123");
final IFunctions.Base64Encoder f = IFunctions.Base64Encoder.INSTANCE;
Assert.assertEquals(Base64.encodeBase64String(value), f.func(value));
}
示例15: getIVSpec
import org.apache.commons.codec.binary.StringUtils; //導入方法依賴的package包/類
private static IvParameterSpec getIVSpec() {
return new IvParameterSpec(StringUtils.getBytesUtf8("%jUS*(Aol(-y)lC/"));
}