Java Code Examples for org.apache.shiro.util.ByteSource#getBytes()

The following examples show how to use org.apache.shiro.util.ByteSource#getBytes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShiroTest.java    From EasyEE with MIT License 6 votes vote down vote up
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);
}
 
Example 2
Source File: ShiroTest.java    From EasyEE with MIT License 6 votes vote down vote up
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);
}
 
Example 3
Source File: MySimpleHash.java    From cms with Apache License 2.0 4 votes vote down vote up
private void hash(ByteSource source, ByteSource salt, int hashIterations) throws CodecException, UnknownAlgorithmException {
    byte[] saltBytes = salt != null ? salt.getBytes() : null;
    byte[] hashedBytes = this.hash(source.getBytes(), saltBytes, hashIterations);
    String toH= Hex.encodeToString(hashedBytes);
    this.setBytes(hashedBytes);
}
 
Example 4
Source File: AES.java    From JavaSecurity with Apache License 2.0 4 votes vote down vote up
private static byte[] decrypt(Key key, byte[] ciphertext) {
    AesCipherService cipherService = new AesCipherService();
    ByteSource plainText = cipherService.decrypt(ciphertext, key.getEncoded());

    return plainText.getBytes();
}
 
Example 5
Source File: AES.java    From JavaSecurity with Apache License 2.0 3 votes vote down vote up
/**
 * 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();
}
 
Example 6
Source File: MySimpleByteSource.java    From VideoMeeting with Apache License 2.0 2 votes vote down vote up
/**
 * 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();
}