本文整理汇总了Java中org.keyczar.exceptions.KeyczarException类的典型用法代码示例。如果您正苦于以下问题:Java KeyczarException类的具体用法?Java KeyczarException怎么用?Java KeyczarException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KeyczarException类属于org.keyczar.exceptions包,在下文中一共展示了KeyczarException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: RsaPrivateStream
import org.keyczar.exceptions.KeyczarException; //导入依赖的package包/类
public RsaPrivateStream()
throws KeyczarException
{
try
{
this.signature = Signature.getInstance("SHA1withRSA");
this.verifyingStream = ((VerifyingStream)RsaPrivateKey.this.publicKey.getStream());
this.cipher = Cipher.getInstance(RsaPrivateKey.this.publicKey.getPadding().cryptAlgorithm);
this.encryptingStream = ((EncryptingStream)RsaPrivateKey.this.publicKey.getStream());
return;
}
catch (GeneralSecurityException localGeneralSecurityException)
{
throw new KeyczarException(localGeneralSecurityException);
}
}
示例2: testCreateExportKey
import org.keyczar.exceptions.KeyczarException; //导入依赖的package包/类
@Test
public void testCreateExportKey() throws KeyczarException {
// create the key, export the public key; 1024 bits is the smallest size
GenericKeyczar keyczar = Util.createKey(
DefaultKeyType.RSA_PRIV, KeyPurpose.DECRYPT_AND_ENCRYPT, 1024);
KeyczarReader publicKeyReader = Util.exportPublicKeys(keyczar);
Encrypter encrypter = new Encrypter(publicKeyReader);
// test that it works
String ciphertext = encrypter.encrypt(MESSAGE);
Crypter crypter = new Crypter(Util.readerFromKeyczar(keyczar));
String decrypted = crypter.decrypt(ciphertext);
assertEquals(MESSAGE, decrypted);
// test a session
StringBuilder longMessage = new StringBuilder("hello message ");
while (longMessage.length() < 500) {
longMessage.append(longMessage);
}
ciphertext = Util.encryptWithSession(encrypter, longMessage.toString());
assertEquals(longMessage.toString(), Util.decryptWithSession(crypter, ciphertext));
}
示例3: testSimple
import org.keyczar.exceptions.KeyczarException; //导入依赖的package包/类
@Test
public void testSimple() throws KeyczarException {
KeyczarReader reader = new KeyczarJsonReader(JSON_KEY);
KeyMetadata metadata = KeyMetadata.read(reader.getMetadata());
assertEquals(0, metadata.getPrimaryVersion().getVersionNumber());
assertEquals(KeyPurpose.DECRYPT_AND_ENCRYPT, metadata.getPurpose());
assertEquals("Imported AES", metadata.getName());
assertEquals(1, metadata.getVersions().size());
assertEquals(0, metadata.getVersions().get(0).getVersionNumber());
assertFalse(metadata.getVersions().get(0).isExportable());
Crypter crypter = new Crypter(reader);
String plaintext = "hello world";
String encrypted = crypter.encrypt(plaintext);
assertTrue(!encrypted.equals(plaintext));
String decrypted = crypter.decrypt(encrypted);
assertEquals(plaintext, decrypted);
// TODO: Add an old version of a key; test decrypting with it
}
示例4: verifyBadSignature
import org.keyczar.exceptions.KeyczarException; //导入依赖的package包/类
@Test
public void verifyBadSignature() throws KeyczarException {
SecretsBundle secrets = SecretsBundle.generateForTest();
final String TOKEN = "token";
String signature = secrets.signToken(TOKEN);
assertTrue(secrets.verifyToken(TOKEN, signature));
assertFalse(secrets.verifyToken(TOKEN, signature + "A"));
// Base64DecodingException
assertFalse(secrets.verifyToken(TOKEN, signature.substring(0, signature.length()-1)));
assertFalse(secrets.verifyToken(TOKEN, signature.substring(0, signature.length()-2)));
// ArrayIndexOutOfBoundsException
assertFalse(secrets.verifyToken(TOKEN, ""));
// change the first byte: version exception
assert signature.charAt(0) == 'A';
assertFalse(secrets.verifyToken(TOKEN, 'B' + signature.substring(1, signature.length())));
}
示例5: processCommand
import org.keyczar.exceptions.KeyczarException; //导入依赖的package包/类
@Override
protected MitroRPC processCommand(MitroRequestContext context)
throws IOException, SQLException, MitroServletException {
RPC.CheckTwoFactorRequiredRequest in = gson.fromJson(context.jsonRequest,
RPC.CheckTwoFactorRequiredRequest.class);
String url = null;
// url stays null if 2fa isn't enabled. else, changes to 2fa login page
if (context.requestor.isTwoFactorAuthEnabled()) {
String token = GetMyPrivateKey.makeLoginTokenString(context.requestor,
in.extensionId, in.deviceId);
String signedToken;
try {
signedToken = TwoFactorSigningService.signToken(token);
} catch (KeyczarException e) {
throw new MitroServletException(e);
}
url = context.requestServerUrl + "/mitro-core/TwoFactorAuth?token="
+ URLEncoder.encode(token, "UTF-8") + "&signature="
+ URLEncoder.encode(signedToken, "UTF-8");
}
RPC.CheckTwoFactorRequiredResponse out = new RPC.CheckTwoFactorRequiredResponse();
out.twoFactorUrl = url;
return out;
}
示例6: AesStream
import org.keyczar.exceptions.KeyczarException; //导入依赖的package包/类
public AesStream()
throws KeyczarException
{
IvParameterSpec localIvParameterSpec = new IvParameterSpec(new byte[16]);
try
{
this.encryptingCipher = Cipher.getInstance(AesKey.this.mode.jceMode);
this.encryptingCipher.init(1, AesKey.this.aesKey, localIvParameterSpec);
this.decryptingCipher = Cipher.getInstance(AesKey.this.mode.jceMode);
this.decryptingCipher.init(2, AesKey.this.aesKey, localIvParameterSpec);
this.signStream = ((SigningStream)AesKey.this.hmacKey.getStream());
return;
}
catch (GeneralSecurityException localGeneralSecurityException)
{
throw new KeyczarException(localGeneralSecurityException);
}
}
示例7: encrypt
import org.keyczar.exceptions.KeyczarException; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* <p>Uses Keyczar client to encrypt the byte array.
*
* @throws EncryptionException if any underlying component fails
*/
@Override
public byte[] encrypt(byte[] plain) throws EncryptionException {
try {
Crypter crypter = getCrypter();
return crypter.encrypt(plain);
} catch (KeyczarException e) {
throw new EncryptionException(e);
}
}
示例8: decrypt
import org.keyczar.exceptions.KeyczarException; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* <p>Uses local Keyczar client to decrypt the byte array.
*
* @throws EncryptionException if any underlying component fails
*/
@Override
public byte[] decrypt(byte[] encrypted) throws EncryptionException {
try {
Crypter crypter = getCrypter();
return crypter.decrypt(encrypted);
} catch (KeyczarException e) {
throw new EncryptionException(e);
}
}
示例9: testTwoFactorEnabledNotVerified
import org.keyczar.exceptions.KeyczarException; //导入依赖的package包/类
@Test(expected=DoTwoFactorAuthException.class)
public void testTwoFactorEnabledNotVerified() throws InvalidKeyException,
NoSuchAlgorithmException, KeyczarException, SQLException, MitroServletException {
// extension should check if 2FA is enabled, but we had a bug where this didn't happen
testReq.encryptedPrivateKey = "some encrypted key";
testProcessCommand(testIdentity);
}
示例10: verify
import org.keyczar.exceptions.KeyczarException; //导入依赖的package包/类
public static void verify(String keyPath, String message, String signaturePath) throws KeyczarException {
// Read the key, possibly decrypting using a password
KeyczarReader reader = Util.readJsonFromPath(keyPath);
Verifier key = new Verifier(reader);
String signature = Util.readFile(signaturePath);
System.out.println("verifying signature on message length " + message.length());
if (!key.verify(message, signature)) {
System.err.println("Signature could not be verified!\n");
System.exit(1);
}
}
示例11: testWriteKey
import org.keyczar.exceptions.KeyczarException; //导入依赖的package包/类
@Test
public void testWriteKey() throws KeyczarException {
// Create a key with zero value
GenericKeyczar keyczar = makeKey();
StringBuilder builder = new StringBuilder();
JsonWriter.write(keyczar, builder);
String serialized = builder.toString();
String substr = "\"0\":\"{\\\"aesKeyString\\\":\\\"AAAAAAAAAA";
assertTrue(serialized.contains(substr));
}
示例12: initSign
import org.keyczar.exceptions.KeyczarException; //导入依赖的package包/类
public final void initSign()
throws KeyczarException
{
try
{
this.signature.initSign(DsaPrivateKey.this.jcePrivateKey);
return;
}
catch (GeneralSecurityException localGeneralSecurityException)
{
throw new KeyczarException(localGeneralSecurityException);
}
}
示例13: main
import org.keyczar.exceptions.KeyczarException; //导入依赖的package包/类
public static void main(String[] arguments) throws KeyczarException {
if (arguments.length != 1) {
System.err.println("JsonWriter (input key path)");
System.err.println(" Reads a key and writes to stdout as JSON");
System.exit(1);
}
GenericKeyczar keyczar = new GenericKeyczar(new KeyczarFileReader(arguments[0]));
write(keyczar, System.out);
}
示例14: sign
import org.keyczar.exceptions.KeyczarException; //导入依赖的package包/类
public final void sign(ByteBuffer paramByteBuffer)
throws KeyczarException
{
try
{
paramByteBuffer.put(this.signature.sign());
return;
}
catch (SignatureException localSignatureException)
{
throw new KeyczarException(localSignatureException);
}
}
示例15: testDoGetIsEnabled
import org.keyczar.exceptions.KeyczarException; //导入依赖的package包/类
@Test
public void testDoGetIsEnabled() throws ServletException, IOException,
InvalidKeyException, NoSuchAlgorithmException, SQLException,
KeyczarException, CryptoError {
MockHttpServletResponse response = testDoGet(null, false, false, false);
assertThat(response.getOutput(), containsString("Enabled"));
testIdentity = DBIdentity.getIdentityForUserName(manager, testIdentity.getName());
assertTrue(testIdentity.getTwoFactorSecret() != null);
}