本文整理汇总了Java中org.springframework.security.crypto.codec.Utf8类的典型用法代码示例。如果您正苦于以下问题:Java Utf8类的具体用法?Java Utf8怎么用?Java Utf8使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Utf8类属于org.springframework.security.crypto.codec包,在下文中一共展示了Utf8类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createToken
import org.springframework.security.crypto.codec.Utf8; //导入依赖的package包/类
@Override
public TokenData createToken(TokenConfiguration config) {
final long creationTime = System.currentTimeMillis();
byte[] serverSecret = computeServerSecretApplicableAt(creationTime);
byte[] content = contentPack(creationTime,
generateRandom(),
serverSecret,
Utf8.encode(pack(config.getUserName(), config.getDeviceHash())));
byte[] sign = sign(content);
ByteBuffer buffer = ByteBuffer.allocate(1 + sign.length + 1 + content.length);
store(buffer, content);
store(buffer, sign);
String key = base32.encodeAsString(buffer.array());
return new TokenDataImpl(creationTime,
TokenUtils.getKeyWithTypeAndToken(TYPE, key),
config.getUserName(),
config.getDeviceHash());
}
示例2: MessageDigestPasswordEncoder
import org.springframework.security.crypto.codec.Utf8; //导入依赖的package包/类
public MessageDigestPasswordEncoder(String algorithm, CharSequence secret) {
try {
messageDigest = MessageDigest.getInstance(algorithm);
} catch (NoSuchAlgorithmException e) {
throw new IllegalStateException("No such hashing algorithm", e);
}
this.secret = Utf8.encode(secret);
this.saltGenerator = KeyGenerators.secureRandom();
}
示例3: createECDSASignature
import org.springframework.security.crypto.codec.Utf8; //导入依赖的package包/类
public static String createECDSASignature(final PrivateKey privateKey, final String payload) throws Exception {
Signature ecdsaSign = Signature.getInstance(SHA1WITH_ECDSA, JCE_PROVIDER);
ecdsaSign.initSign(privateKey);
ecdsaSign.update(Utf8.encode(payload));
return BaseEncoding.base64().encode(ecdsaSign.sign());
}
示例4: verifyECDSASignature
import org.springframework.security.crypto.codec.Utf8; //导入依赖的package包/类
public static boolean verifyECDSASignature(String payload, String signature, PublicKey publicKey) throws Exception {
Signature ecdsaSign = Signature.getInstance(SHA1WITH_ECDSA, JCE_PROVIDER);
ecdsaSign.initVerify(publicKey);
ecdsaSign.update(Utf8.encode(payload));
return ecdsaSign.verify(BaseEncoding.base64().decode(signature));
}
示例5: getToken
import org.springframework.security.crypto.codec.Utf8; //导入依赖的package包/类
@Override
public TokenData getToken(String tokenString) {
final String key = unwrapToken(tokenString);
if (key.isEmpty()) {
return null;
}
byte[] decodedKey = base32.decode(key);
byte[] currentSignature;
final long creationTime;
byte[] random;
byte[] payload;
{
byte[] content;
{
ByteBuffer buffer = ByteBuffer.wrap(decodedKey);
content = restoreArray(buffer);
currentSignature = restoreArray(buffer);
}
ByteBuffer contentBuffer = ByteBuffer.wrap(content);
creationTime = contentBuffer.getLong();
random = restoreArray(contentBuffer);
// we need to skip secret
restoreArray(contentBuffer);
payload = restoreArray(contentBuffer);
}
final byte[] serverSecret = computeServerSecretApplicableAt(creationTime);
// Verification
byte[] expectedSign = sign(contentPack(creationTime, random, serverSecret, payload));
Assert.isTrue(Arrays.equals(expectedSign, currentSignature), "Key verification failure");
String[] unpack = unpack(Utf8.decode(payload));
return new TokenDataImpl(creationTime, TokenUtils.getKeyWithTypeAndToken(TYPE, key), unpack[0], unpack[1]);
}
示例6: encodePassword
import org.springframework.security.crypto.codec.Utf8; //导入依赖的package包/类
private String encodePassword(String rawPass, Object salt, String version) {
// パスワードのencodeのバージョンによって処理を変える
String saltedPass = mergePasswordAndSalt(rawPass, salt, false);
MessageDigest messageDigest = getMessageDigest(version);
byte[] digest = messageDigest.digest(Utf8.encode(saltedPass));
return version + ":" + (new String(Hex.encode(digest)));
}
示例7: computeServerSecretApplicableAt
import org.springframework.security.crypto.codec.Utf8; //导入依赖的package包/类
private byte[] computeServerSecretApplicableAt(long time) {
return Utf8.encode(serverSecret + ":" + (time % serverInteger));
}
示例8: encrypt
import org.springframework.security.crypto.codec.Utf8; //导入依赖的package包/类
public String encrypt(String text) {
return new String(Hex.encode(doFinal(encryptor, Utf8.encode(text))));
}
示例9: decrypt
import org.springframework.security.crypto.codec.Utf8; //导入依赖的package包/类
public String decrypt(String encryptedText) {
return Utf8.decode(doFinal(decryptor, Hex.decode(encryptedText)));
}
示例10: GreenhousePasswordEncoder
import org.springframework.security.crypto.codec.Utf8; //导入依赖的package包/类
/**
* Creates a fully customized standard password encoder.
*/
public GreenhousePasswordEncoder(String algorithm, String provider, String secret) {
this.digester = new Digester(algorithm, provider);
this.secret = Utf8.encode(secret);
this.saltGenerator = KeyGenerators.secureRandom();
}