当前位置: 首页>>代码示例>>Java>>正文


Java PlainText类代码示例

本文整理汇总了Java中org.owasp.esapi.crypto.PlainText的典型用法代码示例。如果您正苦于以下问题:Java PlainText类的具体用法?Java PlainText怎么用?Java PlainText使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PlainText类属于org.owasp.esapi.crypto包,在下文中一共展示了PlainText类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getProperty

import org.owasp.esapi.crypto.PlainText; //导入依赖的package包/类
/**
 * {@inheritDoc}
 *
 * @throws EncryptionRuntimeException Thrown if decryption fails.
 */
@Override
public synchronized String getProperty(String key) throws EncryptionRuntimeException {
    int progressMark = 0;
    try {
        String encryptedValue = super.getProperty(key);

        if(encryptedValue==null)
            return null;

        progressMark = 0;
        byte[] serializedCiphertext   = ESAPI.encoder().decodeFromBase64(encryptedValue);
        progressMark++;
        CipherText restoredCipherText = CipherText.fromPortableSerializedBytes(serializedCiphertext);
        progressMark++;
        PlainText plaintext           = ESAPI.encryptor().decrypt(restoredCipherText);

        return plaintext.toString();
	} catch (Exception e) {
		throw new EncryptionRuntimeException("Property retrieval failure",
				                             "Couldn't retrieve encrypted property for property " + key +
											 GET_ERROR_MESSAGES[progressMark], e);
    }
}
 
开发者ID:abimael93,项目名称:owasp-esapi-java,代码行数:29,代码来源:ReferenceEncryptedProperties.java

示例2: setProperty

import org.owasp.esapi.crypto.PlainText; //导入依赖的package包/类
/**
 * {@inheritDoc}
 *
 * @throws EncryptionRuntimeException Thrown if encryption fails.
 */
@Override
public synchronized String setProperty(String key, String value) throws EncryptionRuntimeException {
    int progressMark = 0;
    try {
        if ( key == null ) {
            throw new NullPointerException("Property name may not be null.");
        }
        if ( value == null ) {
            throw new NullPointerException("Property value may not be null.");
        }
        // NOTE: Not backward compatible w/ ESAPI 1.4.
        PlainText pt = new PlainText(value);
        CipherText ct = ESAPI.encryptor().encrypt(pt);
        progressMark++;
        byte[] serializedCiphertext = ct.asPortableSerializedByteArray();
        progressMark++;
        String b64str = ESAPI.encoder().encodeForBase64(serializedCiphertext, false);
        progressMark++;
        return (String)super.put(key, b64str);
    } catch (Exception e) {
        throw new EncryptionRuntimeException("Property setting failure",
                                      "Couldn't set encrypted property " + key +
                                      SET_ERROR_MESSAGES[progressMark], e);
    }
}
 
开发者ID:abimael93,项目名称:owasp-esapi-java,代码行数:31,代码来源:ReferenceEncryptedProperties.java

示例3: encrypt

import org.owasp.esapi.crypto.PlainText; //导入依赖的package包/类
@Override
public String encrypt(String clearText)
{
    String cryptedText = null;
    try
    {
        CipherText cipherText = ESAPI.encryptor().encrypt(new PlainText(clearText));
        cryptedText = Base64.encodeBytes(cipherText.asPortableSerializedByteArray());
    }
    catch (EncryptionException e)
    {
        LOG.error("EsapiEncryptor.encrypt: "+e.getMessage(), e);
    }
    return cryptedText;
}
 
开发者ID:alfameCom,项目名称:salasanasiilo,代码行数:16,代码来源:EsapiEncryptor.java

示例4: getProperty

import org.owasp.esapi.crypto.PlainText; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
public synchronized String getProperty(String key) throws EncryptionException {
    String[] errorMsgs = new String[] {
            ": failed decoding from base64",
            ": failed to deserialize properly",
            ": failed to decrypt properly"
        };

    int progressMark = 0;
    try {
        String encryptedValue = properties.getProperty(key);

        if(encryptedValue==null)
            return null;

        progressMark = 0;
        byte[] serializedCiphertext   = ESAPI.encoder().decodeFromBase64(encryptedValue);
        progressMark++;
        CipherText restoredCipherText = CipherText.fromPortableSerializedBytes(serializedCiphertext);
        progressMark++;
        PlainText plaintext           = ESAPI.encryptor().decrypt(restoredCipherText);
        
        return plaintext.toString();
    } catch (Exception e) {
        throw new EncryptionException("Property retrieval failure",
                                      "Couldn't retrieve encrypted property for property " + key +
                                      errorMsgs[progressMark], e);
    }
}
 
开发者ID:abimael93,项目名称:owasp-esapi-java,代码行数:32,代码来源:DefaultEncryptedProperties.java

示例5: setProperty

import org.owasp.esapi.crypto.PlainText; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
public synchronized String setProperty(String key, String value) throws EncryptionException {
    String[] errorMsgs = new String[] {
            ": failed to encrypt properly",
            ": failed to serialize correctly",
            ": failed to base64-encode properly",
            ": failed to set base64-encoded value as property. Illegal key name?"
    };

    int progressMark = 0;
    try {
        if ( key == null ) {
            throw new NullPointerException("Property name may not be null.");
        }
        if ( value == null ) {
            throw new NullPointerException("Property value may not be null.");
        }
        // NOTE: Not backward compatible w/ ESAPI 1.4.
        PlainText pt = new PlainText(value);
        CipherText ct = ESAPI.encryptor().encrypt(pt);
        progressMark++;
        byte[] serializedCiphertext = ct.asPortableSerializedByteArray();
        progressMark++;
        String b64str = ESAPI.encoder().encodeForBase64(serializedCiphertext, false);
        progressMark++;
        String encryptedValue = (String)properties.setProperty(key, b64str);
        progressMark++;
        return encryptedValue;
    } catch (Exception e) {
        throw new EncryptionException("Property setting failure",
                                      "Couldn't set encrypted property " + key +
                                      errorMsgs[progressMark], e);
    }
}
 
开发者ID:abimael93,项目名称:owasp-esapi-java,代码行数:37,代码来源:DefaultEncryptedProperties.java

示例6: decryptString

import org.owasp.esapi.crypto.PlainText; //导入依赖的package包/类
private String decryptString(String ciphertext) throws EncryptionException {
    byte[] serializedCiphertext = Hex.decode(ciphertext);
    CipherText restoredCipherText =
        CipherText.fromPortableSerializedBytes(serializedCiphertext);
    PlainText plaintext = ESAPI.encryptor().decrypt(restoredCipherText);
    return plaintext.toString();
}
 
开发者ID:abimael93,项目名称:owasp-esapi-java,代码行数:8,代码来源:DefaultHTTPUtilities.java

示例7: testUnicodeString

import org.owasp.esapi.crypto.PlainText; //导入依赖的package包/类
@Test
public final void testUnicodeString() {
    // These 2 strings are *meant* to be equal. If they are not, please
    // do *NOT* change the test. It's a Windows thing. Sorry. Change your
    // OS instead. ;-)
    if ( ! unicodeStr.equals(altString) ) {
        System.err.println("Skipping JUnit test case " +
                           "PlainTextTest.testUnicodeString() on OS " +
                           System.getProperty("os.name") );
        return;
    }
	try {
		byte[] utf8Bytes = unicodeStr.getBytes("UTF-8");
		PlainText pt1 = new PlainText(unicodeStr);
		PlainText pt2 = new PlainText(altString);
		
		assertTrue( pt1.equals(pt1) );   // Equals self
		assertFalse( pt1.equals(null) );
		assertTrue( pt1.equals(pt2) );
		assertFalse( pt1.equals( unicodeStr ) );
		assertTrue( pt1.length() == utf8Bytes.length );
		assertTrue( Arrays.equals(utf8Bytes, pt1.asBytes()) );			
		assertTrue( pt1.hashCode() == unicodeStr.hashCode() );
		
	} catch (UnsupportedEncodingException e) {
		fail("No UTF-8 byte encoding: " + e);
		e.printStackTrace(System.err);
	}
}
 
开发者ID:abimael93,项目名称:owasp-esapi-java,代码行数:30,代码来源:PlainTextTest.java

示例8: testEmptyString

import org.owasp.esapi.crypto.PlainText; //导入依赖的package包/类
@Test
public final void testEmptyString() {
	PlainText mt  = new PlainText("");
	assertTrue( mt.length() == 0 );
	byte[] ba = mt.asBytes();
	assertTrue( ba != null && ba.length == 0 );
}
 
开发者ID:abimael93,项目名称:owasp-esapi-java,代码行数:8,代码来源:PlainTextTest.java

示例9: testOverwrite

import org.owasp.esapi.crypto.PlainText; //导入依赖的package包/类
@Test
public final void testOverwrite() {
	try {
		byte[] origBytes = unicodeStr.getBytes("UTF-8");
		PlainText pt = new PlainText(origBytes);
		assertTrue( pt.toString().equals(unicodeStr) );
		assertTrue( Arrays.equals(origBytes, pt.asBytes()) );			
		assertTrue( pt.hashCode() == unicodeStr.hashCode() );
		
		int origLen = origBytes.length;

		pt.overwrite();
        byte[] overwrittenBytes = pt.asBytes();
		assertTrue( overwrittenBytes != null );
		assertFalse( Arrays.equals( origBytes, overwrittenBytes ) );

		// Ensure that ALL the bytes overwritten with '*'.
		int afterLen = overwrittenBytes.length;
		assertTrue( origLen == afterLen );
		int sum = 0;
		for( int i = 0; i < afterLen; i++ ) {
		    if ( overwrittenBytes[i] == '*' ) {
		        sum++;
		    }
		}
		assertTrue( afterLen == sum );
	} catch (UnsupportedEncodingException e) {
		fail("No UTF-8 byte encoding: " + e);
		e.printStackTrace(System.err);
	}
}
 
开发者ID:abimael93,项目名称:owasp-esapi-java,代码行数:32,代码来源:PlainTextTest.java

示例10: testEncryptDecrypt1

import org.owasp.esapi.crypto.PlainText; //导入依赖的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);
      }
  }
 
开发者ID:abimael93,项目名称:owasp-esapi-java,代码行数:21,代码来源:EncryptorTest.java

示例11: testEncryptDecrypt2

import org.owasp.esapi.crypto.PlainText; //导入依赖的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);
      }
  }
 
开发者ID:abimael93,项目名称:owasp-esapi-java,代码行数:18,代码来源:EncryptorTest.java

示例12: testEncryptEmptyStrings

import org.owasp.esapi.crypto.PlainText; //导入依赖的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);
    }
}
 
开发者ID:abimael93,项目名称:owasp-esapi-java,代码行数:17,代码来源:EncryptorTest.java

示例13: testDecryptNull

import org.owasp.esapi.crypto.PlainText; //导入依赖的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);
     }
 }
 
开发者ID:abimael93,项目名称:owasp-esapi-java,代码行数:15,代码来源:EncryptorTest.java

示例14: isPlaintextOverwritten

import org.owasp.esapi.crypto.PlainText; //导入依赖的package包/类
private static boolean isPlaintextOverwritten(PlainText plaintext) {
	// Note: An assumption here that the original plaintext did not consist
	// entirely of all '*' characters.
	byte[] ptBytes = plaintext.asBytes();
	
	for ( int i = 0; i < ptBytes.length; i++ ) {
		if ( ptBytes[i] != '*' ) {
			return false;
		}
	}
	return true;
}
 
开发者ID:abimael93,项目名称:owasp-esapi-java,代码行数:13,代码来源:EncryptorTest.java

示例15: testEncryptionSerialization

import org.owasp.esapi.crypto.PlainText; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public void testEncryptionSerialization() throws EncryptionException {
    String secretMsg = "Secret Message";
    ESAPI.securityConfiguration().setCipherTransformation("AES/CBC/PKCS5Padding");
    CipherText ct = ESAPI.encryptor().encrypt(new PlainText(secretMsg));
    
    byte[] serializedCipherText = ct.asPortableSerializedByteArray();
    
    PlainText plainText = ESAPI.encryptor().decrypt(
                            CipherText.fromPortableSerializedBytes(serializedCipherText) );
    
    assertTrue( secretMsg.equals( plainText.toString() ) );
}
 
开发者ID:abimael93,项目名称:owasp-esapi-java,代码行数:14,代码来源:EncryptorTest.java


注:本文中的org.owasp.esapi.crypto.PlainText类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。