org.apache.shiro.codec.CodecSupport Java Examples

The following examples show how to use org.apache.shiro.codec.CodecSupport. 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: AES.java    From JavaSecurity with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    final String initialText = "AES encryption sample text";
    final char[] keystorePassword = "samples".toCharArray();
    final String keyAlias = "symmetric-sample";
    final char[] keyPassword = "symmetric-sample".toCharArray();

    try {
        KeyStore ks = loadKeystore(keystorePassword);
        Key key = loadKey(ks, keyAlias, keyPassword);
        byte[] ciphertext = encrypt(key, CodecSupport.toBytes(initialText));
        byte[] plaintext = decrypt(key, ciphertext);

        printReadableMessages(initialText, ciphertext, plaintext);
    } catch (NoSuchAlgorithmException | KeyStoreException | CertificateException | UnrecoverableKeyException | IOException ex) {
        log.error(ex.getMessage(), ex);
    }
}
 
Example #2
Source File: ShiroByteSource.java    From xmanager with Apache License 2.0 4 votes vote down vote up
public ShiroByteSource(String string) {
	this.bytes = CodecSupport.toBytes(string);
}
 
Example #3
Source File: AES.java    From JavaSecurity with Apache License 2.0 4 votes vote down vote up
private static void printReadableMessages(String initialText, byte[] ciphertext, byte[] plaintext) {
    log.info("initialText: {}", initialText);
    log.info("cipherText as HEX: {}", Hex.encodeToString(ciphertext));
    log.info("plaintext: {}", CodecSupport.toString(plaintext));
}
 
Example #4
Source File: MySimpleByteSource.java    From VideoMeeting with Apache License 2.0 2 votes vote down vote up
/**
 * Creates an instance by converting the characters to a byte array (assumes
 * UTF-8 encoding).
 * 
 * @param chars
 *            the source characters to use to create the underlying byte
 *            array.
 * @since 1.1
 */
public MySimpleByteSource(char[] chars) {
	this.bytes = CodecSupport.toBytes(chars);
}
 
Example #5
Source File: MySimpleByteSource.java    From VideoMeeting with Apache License 2.0 2 votes vote down vote up
/**
 * Creates an instance by converting the String to a byte array (assumes
 * UTF-8 encoding).
 * 
 * @param string
 *            the source string to convert to a byte array (assumes UTF-8
 *            encoding).
 * @since 1.1
 */
public MySimpleByteSource(String string) {
	this.bytes = CodecSupport.toBytes(string);
}
 
Example #6
Source File: SimpleByteSource.java    From nano-framework with Apache License 2.0 2 votes vote down vote up
/**
 * Creates an instance by converting the characters to a byte array (assumes UTF-8 encoding).
 *
 * @param chars the source characters to use to create the underlying byte array.
 * @since 1.1
 */
public SimpleByteSource(char[] chars) {
    this.bytes = CodecSupport.toBytes(chars);
}
 
Example #7
Source File: SimpleByteSource.java    From nano-framework with Apache License 2.0 2 votes vote down vote up
/**
 * Creates an instance by converting the String to a byte array (assumes UTF-8 encoding).
 *
 * @param string the source string to convert to a byte array (assumes UTF-8 encoding).
 * @since 1.1
 */
public SimpleByteSource(String string) {
    this.bytes = CodecSupport.toBytes(string);
}