本文整理汇总了Java中org.owasp.esapi.ESAPI.encryptor方法的典型用法代码示例。如果您正苦于以下问题:Java ESAPI.encryptor方法的具体用法?Java ESAPI.encryptor怎么用?Java ESAPI.encryptor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.owasp.esapi.ESAPI
的用法示例。
在下文中一共展示了ESAPI.encryptor方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createEncryptedToken
import org.owasp.esapi.ESAPI; //导入方法依赖的package包/类
private String createEncryptedToken(SecretKey skey) throws EncryptionException {
StringBuilder sb = new StringBuilder( getUserAccountName() + DELIM);
// CHECKME: Should we check here to see if token has already expired
// and refuse to encrypt it (by throwing exception) if it has???
// If so, then updateToken() should also be revisited.
sb.append( getExpiration() ).append( DELIM );
sb.append( getQuotedAttributes() );
Encryptor encryptor = ESAPI.encryptor();
CipherText ct = encryptor.encrypt(skey, new PlainText( sb.toString() ) );
String b64 =
ESAPI.encoder().encodeForBase64(ct.asPortableSerializedByteArray(),
false);
return b64;
}
示例2: testHash
import org.owasp.esapi.ESAPI; //导入方法依赖的package包/类
/**
* Test of hash method, of class org.owasp.esapi.Encryptor.
*
* @throws EncryptionException
*/
public void testHash() throws EncryptionException {
System.out.println("testHash()");
Encryptor instance = ESAPI.encryptor();
String hash1 = instance.hash("test1", "salt");
String hash2 = instance.hash("test2", "salt");
assertFalse(hash1.equals(hash2));
String hash3 = instance.hash("test", "salt1");
String hash4 = instance.hash("test", "salt2");
assertFalse(hash3.equals(hash4));
}
示例3: testEncryptDecrypt1
import org.owasp.esapi.ESAPI; //导入方法依赖的package包/类
/**
* Test of new encrypt / decrypt method for Strings whose length is
* not a multiple of the cipher block size (16 bytes for AES).
*
* @throws EncryptionException
* the encryption exception
*/
public void testEncryptDecrypt1() throws EncryptionException {
System.out.println("testEncryptDecrypt2()");
Encryptor instance = ESAPI.encryptor();
String plaintext = "test1234test1234tes"; // Not a multiple of block size (16 bytes)
try {
CipherText ct = instance.encrypt(new PlainText(plaintext));
PlainText pt = instance.decrypt(ct);
assertTrue( pt.toString().equals(plaintext) );
}
catch( EncryptionException e ) {
fail("testEncryptDecrypt2(): Caught exception: " + e);
}
}
示例4: testEncryptDecrypt2
import org.owasp.esapi.ESAPI; //导入方法依赖的package包/类
/**
* Test of new encrypt / decrypt method for Strings whose length is
* same as cipher block size (16 bytes for AES).
*/
public void testEncryptDecrypt2() {
System.out.println("testEncryptDecrypt2()");
Encryptor instance = ESAPI.encryptor();
String plaintext = "test1234test1234";
try {
CipherText ct = instance.encrypt(new PlainText(plaintext));
PlainText pt = instance.decrypt(ct);
assertTrue( pt.toString().equals(plaintext) );
}
catch( EncryptionException e ) {
fail("testEncryptDecrypt2(): Caught exception: " + e);
}
}
示例5: testEncryptEmptyStrings
import org.owasp.esapi.ESAPI; //导入方法依赖的package包/类
/**
* Test of encrypt methods for empty String.
*/
public void testEncryptEmptyStrings() {
System.out.println("testEncryptEmptyStrings()");
Encryptor instance = ESAPI.encryptor();
String plaintext = "";
try {
// System.out.println("New encryption methods");
CipherText ct = instance.encrypt(new PlainText(plaintext));
PlainText pt = instance.decrypt(ct);
assertTrue( pt.toString().equals("") );
} catch(Exception e) {
fail("testEncryptEmptyStrings() -- Caught exception: " + e);
}
}
示例6: testEncryptNull
import org.owasp.esapi.ESAPI; //导入方法依赖的package包/类
/**
* Test encryption method for null.
*/
public void testEncryptNull() {
System.out.println("testEncryptNull()");
Encryptor instance = ESAPI.encryptor();
try {
CipherText ct = instance.encrypt( null ); // Should throw NPE or AssertionError
fail("New encrypt(PlainText) method did not throw. Result was: " + ct.toString());
} catch(Throwable t) {
// It should be one of these, depending on whether or not assertions are enabled.
assertTrue( t instanceof IllegalArgumentException || t instanceof AssertionError);
}
}
示例7: testDecryptNull
import org.owasp.esapi.ESAPI; //导入方法依赖的package包/类
/**
* Test decryption method for null.
*/
public void testDecryptNull() {
System.out.println("testDecryptNull()");
Encryptor instance = ESAPI.encryptor();
try {
PlainText pt = instance.decrypt( null ); // Should throw IllegalArgumentException or AssertionError
fail("New decrypt(PlainText) method did not throw. Result was: " + pt.toString());
} catch(Throwable t) {
// It should be one of these, depending on whether or not assertions are enabled.
assertTrue( t instanceof IllegalArgumentException || t instanceof AssertionError);
}
}
示例8: testSign
import org.owasp.esapi.ESAPI; //导入方法依赖的package包/类
/**
* Test of sign method, of class org.owasp.esapi.Encryptor.
*
* @throws EncryptionException
* the encryption exception
*/
public void testSign() throws EncryptionException {
System.out.println("testSign()");
Encryptor instance = ESAPI.encryptor();
String plaintext = ESAPI.randomizer().getRandomString( 32, EncoderConstants.CHAR_ALPHANUMERICS );
String signature = instance.sign(plaintext);
assertTrue( instance.verifySignature( signature, plaintext ) );
assertFalse( instance.verifySignature( signature, "ridiculous" ) );
assertFalse( instance.verifySignature( "ridiculous", plaintext ) );
}
示例9: testVerifySignature
import org.owasp.esapi.ESAPI; //导入方法依赖的package包/类
/**
* Test of verifySignature method, of class org.owasp.esapi.Encryptor.
*
* @throws EncryptionException
* the encryption exception
*/
public void testVerifySignature() throws EncryptionException {
System.out.println("testVerifySignature()");
Encryptor instance = ESAPI.encryptor();
String plaintext = ESAPI.randomizer().getRandomString( 32, EncoderConstants.CHAR_ALPHANUMERICS );
String signature = instance.sign(plaintext);
assertTrue( instance.verifySignature( signature, plaintext ) );
}