本文整理匯總了Java中org.apache.shiro.util.ByteSource.getBytes方法的典型用法代碼示例。如果您正苦於以下問題:Java ByteSource.getBytes方法的具體用法?Java ByteSource.getBytes怎麽用?Java ByteSource.getBytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.shiro.util.ByteSource
的用法示例。
在下文中一共展示了ByteSource.getBytes方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: passwordsMatch
import org.apache.shiro.util.ByteSource; //導入方法依賴的package包/類
public boolean passwordsMatch(Object submittedPlaintext, String encrypted) {
ByteSource plaintextBytes = ByteSource.Util.bytes(submittedPlaintext);
if (encrypted == null || encrypted.length() == 0) {
return plaintextBytes == null || plaintextBytes.isEmpty();
} else {
if (plaintextBytes == null || plaintextBytes.isEmpty()) {
return false;
}
}
String plaintext = new String(plaintextBytes.getBytes());
String[] tokens = encrypted.split("\\$");
int iterations = Integer.parseInt(tokens[1]);
byte[] salt = tokens[2].getBytes();
String hash = tokens[3];
KeySpec spec = new PBEKeySpec(plaintext.toCharArray(), salt, iterations, 256);
try {
String algorithmName = getAlgorithmFullName(tokens[0]);
SecretKeyFactory f = SecretKeyFactory.getInstance(algorithmName);
return hash.equals(Base64.encodeToString(f.generateSecret(spec).getEncoded()));
} catch (Exception e) {
log.error(e.getMessage());
return false;
}
}
示例2: main
import org.apache.shiro.util.ByteSource; //導入方法依賴的package包/類
public static void main(String[] args) {
String base64="zGkG0zevFbnIioooS3MfnnbWeBUeiZrScKVJms0CZAdJ2MYTddPkvBHGmMhvgdKA5QJk8FSb9T1Y1tFlUnnCsIvcK+iX4cfrwD7voGdU5bW9AWjwNvl3BDrAgRf+hvjrI3T5nBTFeW7uI6GzfFrIx92qER9lQ97g19Dn555uwIzf0ULvc8jICZTraLLrf2avh1hy2kUJJblO6u5IHiBbAXBNitZ6W1yjLEWmSFnb+EsEWAGB3WwV1u1HZO045LB4G57UIH4QGM0xfJjWWeahiTS4j9IAEJBbghwfL1A5pdzFiXJzzA5GF85vtP+6jLwQfGaQJyv35PvNNsDmCqFe8eUSBLji5z5y/y+yKfZk9izXiEvFjKQ5kqMqKfLMp+Vn5OuO+syc4CfJL4PLI16vwVUPV1EWAzyxUhK7DtD5OMVcLPwVtwZ11dG88wkZtjXvBymLyGCj5/Tk8gTWYsdcNKD5i8WvbMLT45S4iWsZxa/5offIiCipkkqoqvxCppJLTzBoaR/wlqoa1Bc/cvpijiJTIbSCj+iFloQRdax1mMQ";
base64 = ensurePadding(base64);
byte[] decoded = Base64.decode(base64);
byte[] serialized = decoded;
CipherService cipherService = new AesCipherService();
if (cipherService != null) {
ByteSource byteSource = cipherService.decrypt(decoded, new byte[]{-112, -15, -2, 108, -116, 100, -28, 61, -99, 121, -104, -120, -59, -58, -102, 104});
serialized = byteSource.getBytes();
}
Serializer<PrincipalCollection> serializer = new DefaultSerializer<PrincipalCollection>();
;
System.out.println(serializer.deserialize(serialized));
SimplePrincipalCollection p=(SimplePrincipalCollection) serializer.deserialize(serialized);
System.out.println(p.getPrimaryPrincipal());
System.out.println(p.getRealmNames());
System.out.println(p);
}
示例3: encrypt
import org.apache.shiro.util.ByteSource; //導入方法依賴的package包/類
/**
* Encrypts the byte array by using the configured {@link #getCipherService() cipherService}.
*
* @param serialized the serialized object byte array to be encrypted
* @return an encrypted byte array returned by the configured {@link #getCipherService () cipher}.
*/
protected byte[] encrypt(byte[] serialized) {
byte[] value = serialized;
CipherService cipherService = getCipherService();
if (cipherService != null) {
ByteSource byteSource = cipherService.encrypt(serialized, getEncryptionCipherKey());
value = byteSource.getBytes();
}
return value;
}
示例4: decrypt
import org.apache.shiro.util.ByteSource; //導入方法依賴的package包/類
/**
* Decrypts the byte array using the configured {@link #getCipherService() cipherService}.
*
* @param encrypted the encrypted byte array to decrypt
* @return the decrypted byte array returned by the configured {@link #getCipherService () cipher}.
*/
protected byte[] decrypt(byte[] encrypted) {
byte[] serialized = encrypted;
CipherService cipherService = getCipherService();
if (cipherService != null) {
ByteSource byteSource = cipherService.decrypt(encrypted, getDecryptionCipherKey());
serialized = byteSource.getBytes();
}
return serialized;
}
示例5: toBytes
import org.apache.shiro.util.ByteSource; //導入方法依賴的package包/類
private List<Byte> toBytes(final ByteSource byteSource) {
Vector<Byte> v = new Vector<Byte>();
for (byte b : byteSource.getBytes()) {
v.add(b);
}
return v;
}
示例6: hash
import org.apache.shiro.util.ByteSource; //導入方法依賴的package包/類
private void hash(ByteSource source, ByteSource salt, int hashIterations) throws CodecException, UnknownAlgorithmException {
byte[] saltBytes = salt != null ? salt.getBytes() : null;
byte[] hashedBytes = hash(source.getBytes(), saltBytes, hashIterations);
setBytes(hashedBytes);
}
示例7: decrypt
import org.apache.shiro.util.ByteSource; //導入方法依賴的package包/類
private static byte[] decrypt(Key key, byte[] ciphertext) {
AesCipherService cipherService = new AesCipherService();
ByteSource plainText = cipherService.decrypt(ciphertext, key.getEncoded());
return plainText.getBytes();
}
示例8: encrypt
import org.apache.shiro.util.ByteSource; //導入方法依賴的package包/類
/**
* Encrypts the given text using all Shiro defaults: 128 bit size, CBC mode, PKCS5 padding scheme.
*
* @param key The key to use
* @param initialText The text to encrypt
* @return The encrypted text
*/
private static byte[] encrypt(Key key, byte[] initialText) {
AesCipherService cipherService = new AesCipherService();
ByteSource cipherText = cipherService.encrypt(initialText, key.getEncoded());
return cipherText.getBytes();
}
示例9: MyByteSource
import org.apache.shiro.util.ByteSource; //導入方法依賴的package包/類
/**
* Creates an instance using the sources bytes directly - it does not create a copy of the
* argument's byte array.
*
* @param source the source to use to populate the underlying byte array.
* @since 1.1
*/
public MyByteSource(ByteSource source) {
this.bytes = source.getBytes();
}
示例10: MySimpleByteSource
import org.apache.shiro.util.ByteSource; //導入方法依賴的package包/類
/**
* Creates an instance using the sources bytes directly - it does not create
* a copy of the argument's byte array.
*
* @param source
* the source to use to populate the underlying byte array.
* @since 1.1
*/
public MySimpleByteSource(ByteSource source) {
this.bytes = source.getBytes();
}