本文整理汇总了Java中org.apache.commons.codec.BinaryEncoder类的典型用法代码示例。如果您正苦于以下问题:Java BinaryEncoder类的具体用法?Java BinaryEncoder怎么用?Java BinaryEncoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BinaryEncoder类属于org.apache.commons.codec包,在下文中一共展示了BinaryEncoder类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAsBinaryEncoder
import org.apache.commons.codec.BinaryEncoder; //导入依赖的package包/类
@Test
public void testAsBinaryEncoder() throws EncoderException {
final BinaryEncoder encoder =
(BinaryEncoder) RareBinaryEncoderProxy.newInstance();
try {
encoder.encode((byte[]) null);
Assert.fail("passed: encode((byte[]) null)");
} catch (final NullPointerException npe) {
// expected
}
final byte[] expected = new byte[0];
final byte[] actual = encoder.encode(expected);
Assert.assertEquals(actual, expected);
}
示例2: testAsBinaryEncoder
import org.apache.commons.codec.BinaryEncoder; //导入依赖的package包/类
@Test
public void testAsBinaryEncoder() throws EncoderException {
final BinaryEncoder encoder =
(BinaryEncoder) HexBinaryEncoderProxy.newInstance();
try {
encoder.encode((byte[]) null);
Assert.fail("passed: encode((byte[]) null)");
} catch (final NullPointerException npe) {
// expected
}
final byte[] decoded = Tests.decodedBytes();
final byte[] encoded = encoder.encode(decoded);
}
示例3: getDefaultDeployment
import org.apache.commons.codec.BinaryEncoder; //导入依赖的package包/类
protected static WebArchive getDefaultDeployment(TestContext context) {
context.setAppEngineWebXmlFile("appengine-web-with-logging-properties.xml");
WebArchive war = getTckDeployment(context);
war.addClasses(LoggingTestBase.class, TestBase.class)
// classes for Base64.isBase64()
.addClasses(Base64.class, BaseNCodec.class)
.addClasses(BinaryEncoder.class, Encoder.class)
.addClasses(BinaryDecoder.class, Decoder.class)
.addClasses(EncoderException.class, DecoderException.class)
.addAsWebInfResource("currentTimeUsec.jsp")
.addAsWebInfResource("doNothing.jsp")
.addAsWebInfResource("storeTestData.jsp")
.addAsWebInfResource("throwException.jsp")
.addAsWebInfResource("log4j-test.properties")
.addAsWebInfResource("logging-all.properties");
return war;
}
示例4: testBinaryEncoder
import org.apache.commons.codec.BinaryEncoder; //导入依赖的package包/类
/**
* Tests to make sure Base64's implementation of the org.apache.commons.codec.BinaryEncoder
* interface is behaving identical to commons-codec-1.3.jar.
*
* @throws EncoderException problem
*/
@Test
public void testBinaryEncoder() throws EncoderException {
final BinaryEncoder enc = new Base64();
for (int i = 0; i < STRINGS.length; i++) {
if (STRINGS[i] != null) {
final byte[] base64 = utf8(STRINGS[i]);
final byte[] binary = BYTES[i];
final boolean b = Arrays.equals(base64, enc.encode(binary));
assertTrue("BinaryEncoder test-" + i, b);
}
}
}
示例5: doTest
import org.apache.commons.codec.BinaryEncoder; //导入依赖的package包/类
private <TCoder extends BinaryEncoder & BinaryDecoder> void doTest(String plain, String key, String iv, TCoder coder)
{
AESCipher cipher = new AESCipher();
if (coder != null)
{
cipher.setCoder(coder);
}
cipher.setKey(key, iv);
// Encrypt.
String encrypted = cipher.encrypt(plain);
if (iv == null)
{
byte[] iv2 = cipher.getCipher().getIV();
cipher.setKey(key, iv2);
}
// Decrypt.
String decrypted = cipher.decrypt(encrypted);
if (DEBUG)
{
System.out.println("----------");
System.out.println("codec = " + ((coder != null) ? coder.getClass().getSimpleName() : "default"));
System.out.println("plain = " + plain);
System.out.println("encrypted = " + encrypted);
System.out.println("decrypted = " + decrypted);
}
assertNotEquals(plain, encrypted);
assertEquals(plain, decrypted);
}
示例6: getHelperDeployment
import org.apache.commons.codec.BinaryEncoder; //导入依赖的package包/类
protected static WebArchive getHelperDeployment() {
WebArchive war = getTckDeployment();
war.addClass(DatastoreHelperTestBase.class)
.addClasses(Base64.class, BaseNCodec.class)
.addClasses(BinaryEncoder.class, Encoder.class)
.addClasses(BinaryDecoder.class, Decoder.class)
.addClasses(EncoderException.class, DecoderException.class);
return war;
}
示例7: CodecCipher
import org.apache.commons.codec.BinaryEncoder; //导入依赖的package包/类
/**
* Constructor with a cipher, an encoder and a decoder.
*
* @param cipher
* A cipher. If {@code null} is given, {@link #setCipher(Cipher)}
* must be called later with a valid cipher.
*
* @param encoder
* An encoder used in {@link #encrypt(String)} and
* {@link #encrypt(byte[])} to encode an encrypted byte array.
* If {@code null} is given, {@link Base64} is used as the default
* encoder.
*
* @param decoder
* A decoder used in {@link #decrypt(String)} and
* {@link #decrypt(byte[])} to decode an encoded input byte array.
* If {@code null} is given, {@link Base64} is used as the default
* decoder.
*/
public CodecCipher(Cipher cipher, BinaryEncoder encoder, BinaryDecoder decoder)
{
this.cipher = cipher;
this.encoder = encoder;
this.decoder = decoder;
}
示例8: setEncoder
import org.apache.commons.codec.BinaryEncoder; //导入依赖的package包/类
/**
* Set an encoder.
*
* @param encoder
* An encoder used by {@link #encrypt(String)} and
* {@link #encrypt(byte[])}.
*
* @return
* {@code this} object.
*/
public CodecCipher setEncoder(BinaryEncoder encoder)
{
this.encoder = encoder;
return this;
}
示例9: setCoder
import org.apache.commons.codec.BinaryEncoder; //导入依赖的package包/类
/**
* Set a coder.
*
* @param coder
* A coder which works as both an encoder and a decoder.
* If {@code null} is given, {@link Base64} is used as the
* default coder.
*
* @return
* {@code this} object.
*/
public <TCoder extends BinaryEncoder & BinaryDecoder> CodecCipher setCoder(TCoder coder)
{
this.encoder = coder;
this.decoder = coder;
return this;
}
示例10: DefaultHasher
import org.apache.commons.codec.BinaryEncoder; //导入依赖的package包/类
/**
* Builds a utility to hash values based on a given algorithm.
* @param algorithm The algorithm used when hashing a value.
* @param encoder The encoder to use to encode the hashed value.
* @param charset The charset that will be used during hashing and encoding.
* @see java.security.Security
* @see java.security.MessageDigest
*/
public DefaultHasher(final String algorithm, final BinaryEncoder encoder, final Charset charset) {
this.algorithm = algorithm;
this.encoder = encoder;
this.charset = charset;
}
示例11: AESCipher
import org.apache.commons.codec.BinaryEncoder; //导入依赖的package包/类
/**
* Constructor with an encoder and a decoder.
*
* <p>
* This constructor just performs {@link CodecCipher#CodecCipher(String,
* BinaryEncoder, BinaryDecoder) super("AES/CBC/PKCS5Padding", encoder, decoder)}.
* </p>
*
* @param encoder
* An encoder used in {@link #encrypt(String) encrypt(String)} and
* {@link #encrypt(byte[]) encrypt(byte[])} to encode an encrypted byte array.
* If {@code null} is given, {@link Base64} is used as the default
* encoder.
*
* @param decoder
* A decoder used in {@link #decrypt(String) decrypt(String)} and
* {@link #decrypt(byte[]) decrypt(byte[])} to decode an encoded input byte array.
* If {@code null} is given, {@link Base64} is used as the default
* decoder.
*/
public AESCipher(BinaryEncoder encoder, BinaryDecoder decoder)
{
super(TRANSFORMATION, encoder, decoder);
}
示例12: getEncoder
import org.apache.commons.codec.BinaryEncoder; //导入依赖的package包/类
/**
* Get the encoder which this instance internally holds.
*
* @return
* The internal encoder. This may be {@code null}, and
* in such a case, {@link #encrypt(String)} and
* {@link #encrypt(byte[])} use {@link Base64}.
*/
public BinaryEncoder getEncoder()
{
return encoder;
}