本文整理汇总了Java中org.bouncycastle.util.Strings.toUTF8ByteArray方法的典型用法代码示例。如果您正苦于以下问题:Java Strings.toUTF8ByteArray方法的具体用法?Java Strings.toUTF8ByteArray怎么用?Java Strings.toUTF8ByteArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.util.Strings
的用法示例。
在下文中一共展示了Strings.toUTF8ByteArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSelector
import org.bouncycastle.util.Strings; //导入方法依赖的package包/类
/**
* Create a selector for the passed in email address.
* @param emailAddress the emails address of interest.
* @throws DANEException in case of issue generating a matching name.
*/
public DANEEntrySelector createSelector(String emailAddress)
throws DANEException
{
final byte[] enc = Strings.toUTF8ByteArray(emailAddress.substring(0, emailAddress.indexOf('@')));
try
{
OutputStream cOut = digestCalculator.getOutputStream();
cOut.write(enc);
cOut.close();
}
catch (IOException e)
{
throw new DANEException("Unable to calculate digest string: " + e.getMessage(), e);
}
byte[] hash = digestCalculator.getDigest();
final String domainName = Strings.fromByteArray(Hex.encode(hash)) + "._smimecert." + emailAddress.substring(emailAddress.indexOf('@') + 1);
return new DANEEntrySelector(domainName);
}
示例2: updateDigestIncludingSize
import org.bouncycastle.util.Strings; //导入方法依赖的package包/类
private static void updateDigestIncludingSize(Digest digest, String string)
{
byte[] byteArray = Strings.toUTF8ByteArray(string);
digest.update(intToByteArray(byteArray.length), 0, 4);
digest.update(byteArray, 0, byteArray.length);
Arrays.fill(byteArray, (byte)0);
}
示例3: PKCS5PasswordToUTF8Bytes
import org.bouncycastle.util.Strings; //导入方法依赖的package包/类
/**
* converts a password to a byte array according to the scheme in
* PKCS5 (UTF-8, no padding)
*
* @param password a character array representing the password.
* @return a byte array representing the password.
*/
public static byte[] PKCS5PasswordToUTF8Bytes(
char[] password)
{
if (password != null)
{
return Strings.toUTF8ByteArray(password);
}
else
{
return new byte[0];
}
}
示例4: createData
import org.bouncycastle.util.Strings; //导入方法依赖的package包/类
private static byte[] createData(byte reason, String description)
{
byte[] descriptionBytes = Strings.toUTF8ByteArray(description);
byte[] data = new byte[1 + descriptionBytes.length];
data[0] = reason;
System.arraycopy(descriptionBytes, 0, data, 1, descriptionBytes.length);
return data;
}
示例5: genCalculator
import org.bouncycastle.util.Strings; //导入方法依赖的package包/类
private MacCalculator genCalculator(final PBMParameter params, char[] password)
throws CRMFException
{
// From RFC 4211
//
// 1. Generate a random salt value S
//
// 2. Append the salt to the pw. K = pw || salt.
//
// 3. Hash the value of K. K = HASH(K)
//
// 4. Iter = Iter - 1. If Iter is greater than zero. Goto step 3.
//
// 5. Compute an HMAC as documented in [HMAC].
//
// MAC = HASH( K XOR opad, HASH( K XOR ipad, data) )
//
// Where opad and ipad are defined in [HMAC].
byte[] pw = Strings.toUTF8ByteArray(password);
byte[] salt = params.getSalt().getOctets();
byte[] K = new byte[pw.length + salt.length];
System.arraycopy(pw, 0, K, 0, pw.length);
System.arraycopy(salt, 0, K, pw.length, salt.length);
calculator.setup(params.getOwf(), params.getMac());
int iter = params.getIterationCount().getValue().intValue();
do
{
K = calculator.calculateDigest(K);
}
while (--iter > 0);
final byte[] key = K;
return new MacCalculator()
{
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
public AlgorithmIdentifier getAlgorithmIdentifier()
{
return new AlgorithmIdentifier(CMPObjectIdentifiers.passwordBasedMac, params);
}
public GenericKey getKey()
{
return new GenericKey(getAlgorithmIdentifier(), key);
}
public OutputStream getOutputStream()
{
return bOut;
}
public byte[] getMac()
{
try
{
return calculator.calculateMac(key, bOut.toByteArray());
}
catch (CRMFException e)
{
throw new RuntimeOperatorException("exception calculating mac: " + e.getMessage(), e);
}
}
};
}
示例6: calculateS
import org.bouncycastle.util.Strings; //导入方法依赖的package包/类
/**
* Converts the given password to a {@link BigInteger}
* for use in arithmetic calculations.
*/
public static BigInteger calculateS(char[] password)
{
return new BigInteger(Strings.toUTF8ByteArray(password));
}
示例7: updateDigest
import org.bouncycastle.util.Strings; //导入方法依赖的package包/类
private static void updateDigest(Digest digest, String string)
{
byte[] byteArray = Strings.toUTF8ByteArray(string);
digest.update(byteArray, 0, byteArray.length);
Arrays.fill(byteArray, (byte)0);
}
示例8: updateMac
import org.bouncycastle.util.Strings; //导入方法依赖的package包/类
private static void updateMac(Mac mac, String string)
{
byte[] byteArray = Strings.toUTF8ByteArray(string);
mac.update(byteArray, 0, byteArray.length);
Arrays.fill(byteArray, (byte)0);
}
示例9: DERT61UTF8String
import org.bouncycastle.util.Strings; //导入方法依赖的package包/类
/**
* basic constructor - with string UTF8 conversion assumed.
*/
public DERT61UTF8String(
String string)
{
this(Strings.toUTF8ByteArray(string));
}
示例10: DERUTF8String
import org.bouncycastle.util.Strings; //导入方法依赖的package包/类
/**
* basic constructor
*/
public DERUTF8String(String string)
{
this.string = Strings.toUTF8ByteArray(string);
}
示例11: generate
import org.bouncycastle.util.Strings; //导入方法依赖的package包/类
/**
* Creates a 60 character Bcrypt String, including
* version, cost factor, salt and hash, separated by '$'
*
* @param cost the cost factor, treated as an exponent of 2
* @param salt a 16 byte salt
* @param password the password
* @return a 60 character Bcrypt String
*/
public static String generate(
char[] password,
byte[] salt,
int cost)
{
if (password == null)
{
throw new IllegalArgumentException("Password required.");
}
if (salt == null)
{
throw new IllegalArgumentException("Salt required.");
}
else if (salt.length != 16)
{
throw new DataLengthException("16 byte salt required: " + salt.length);
}
if (cost < 4 || cost > 31) // Minimum rounds: 16, maximum 2^31
{
throw new IllegalArgumentException("Invalid cost factor.");
}
byte[] psw = Strings.toUTF8ByteArray(password);
// 0 termination:
byte[] tmp = new byte[psw.length >= 72 ? 72 : psw.length + 1];
if (tmp.length > psw.length)
{
System.arraycopy(psw, 0, tmp, 0, psw.length);
}
else
{
System.arraycopy(psw, 0, tmp, 0, tmp.length);
}
Arrays.fill(psw, (byte)0);
String rv = createBcryptString(tmp, salt, cost);
Arrays.fill(tmp, (byte)0);
return rv;
}
示例12: createData
import org.bouncycastle.util.Strings; //导入方法依赖的package包/类
private static byte[] createData(boolean humanReadable, String notationName, String notationValue)
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
// (4 octets of flags, 2 octets of name length (M),
// 2 octets of value length (N),
// M octets of name data,
// N octets of value data)
// flags
out.write(humanReadable ? 0x80 : 0x00);
out.write(0x0);
out.write(0x0);
out.write(0x0);
byte[] nameData, valueData = null;
int nameLength, valueLength;
nameData = Strings.toUTF8ByteArray(notationName);
nameLength = Math.min(nameData.length, 0xFFFF);
if (nameLength != nameData.length)
{
throw new IllegalArgumentException("notationName exceeds maximum length.");
}
valueData = Strings.toUTF8ByteArray(notationValue);
valueLength = Math.min(valueData.length, 0xFFFF);
if (valueLength != valueData.length)
{
throw new IllegalArgumentException("notationValue exceeds maximum length.");
}
// name length
out.write((nameLength >>> 8) & 0xFF);
out.write((nameLength >>> 0) & 0xFF);
// value length
out.write((valueLength >>> 8) & 0xFF);
out.write((valueLength >>> 0) & 0xFF);
// name
out.write(nameData, 0, nameLength);
// value
out.write(valueData, 0, valueLength);
return out.toByteArray();
}
示例13: SignerUserID
import org.bouncycastle.util.Strings; //导入方法依赖的package包/类
public SignerUserID(
boolean critical,
String userID)
{
super(SignatureSubpacketTags.SIGNER_USER_ID, critical, false, Strings.toUTF8ByteArray(userID));
}
示例14: BasicTlsPSKIdentity
import org.bouncycastle.util.Strings; //导入方法依赖的package包/类
public BasicTlsPSKIdentity(String identity, byte[] psk)
{
this.identity = Strings.toUTF8ByteArray(identity);
this.psk = Arrays.clone(psk);
}
示例15: PKCS5PasswordToUTF8Bytes
import org.bouncycastle.util.Strings; //导入方法依赖的package包/类
/**
* converts a password to a byte array according to the scheme in
* PKCS5 (UTF-8, no padding)
*
* @param password a character array reqpresenting the password.
* @return a byte array representing the password.
*/
public static byte[] PKCS5PasswordToUTF8Bytes(
char[] password)
{
return Strings.toUTF8ByteArray(password);
}