本文整理汇总了Java中org.keyczar.exceptions.KeyczarException类的典型用法代码示例。如果您正苦于以下问题:Java KeyczarException类的具体用法?Java KeyczarException怎么用?Java KeyczarException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KeyczarException类属于org.keyczar.exceptions包,在下文中一共展示了KeyczarException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
}
开发者ID:ChiangC,项目名称:FMTech,代码行数:17,代码来源:RsaPrivateKey.java
示例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));
}
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:24,代码来源:UtilTest.java
示例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
}
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:22,代码来源:KeyczarJsonReaderTest.java
示例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())));
}
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:19,代码来源:SecretsBundleTest.java
示例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;
}
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:25,代码来源:CheckTwoFactorRequired.java
示例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);
}
}
开发者ID:ChiangC,项目名称:FMTech,代码行数:19,代码来源:AesKey.java
示例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);
}
}
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:17,代码来源:KeyczarEncryptor.java
示例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);
}
}
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:17,代码来源:KeyczarEncryptor.java
示例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);
}
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:8,代码来源:EditEncryptedPrivateKeyTest.java
示例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);
}
}
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:13,代码来源:RoundTripper.java
示例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));
}
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:13,代码来源:JsonWriterTest.java
示例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);
}
}
开发者ID:ChiangC,项目名称:FMTech,代码行数:14,代码来源:DsaPrivateKey.java
示例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);
}
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:11,代码来源:JsonWriter.java
示例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);
}
}
开发者ID:ChiangC,项目名称:FMTech,代码行数:14,代码来源:DsaPrivateKey.java
示例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);
}
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:10,代码来源:TFAPreferencesTest.java
示例16: encryptWithSession
import org.keyczar.exceptions.KeyczarException; //导入依赖的package包/类
/**
* Encrypts plaintext with a new session key, which is encrypted using crypter. The encrypted session
* key and encrypted message are packed together using lenPrefixPack().
*/
public static byte[] encryptWithSession(Encrypter crypter, byte[] plaintext) throws KeyczarException {
// Create a session crypter
SessionCrypter session = new SessionCrypter(crypter);
byte[] rawEncrypted = session.encrypt(plaintext);
byte[][] input = {session.getSessionMaterial(), rawEncrypted};
return org.keyczar.util.Util.lenPrefixPack(input);
}
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:12,代码来源:Util.java
示例17: decryptSession
import org.keyczar.exceptions.KeyczarException; //导入依赖的package包/类
public static String decryptSession(String keyPath, String inPath, String expectedMessage) throws KeyczarException {
KeyczarReader reader = Util.readJsonFromPath(keyPath);
String input = Util.readFile(inPath);
String output = Util.decryptWithSession(new Crypter(reader), input);
if (expectedMessage != null && !output.equals(expectedMessage)) {
System.err.println("Session decryption does not match?\n" + output);
System.exit(1);
}
return output;
}
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:12,代码来源:RoundTripper.java
示例18: testReadEncryptedKey
import org.keyczar.exceptions.KeyczarException; //导入依赖的package包/类
@Test
public void testReadEncryptedKey() throws KeyczarException {
KeyczarReader staticReader = new KeyczarReader() {
@Override
public String getKey() throws KeyczarException {
return JSON_KEY;
}
@Override
public String getKey(int version) throws KeyczarException {
assert version == 1;
return JSON_KEY;
}
@Override
public String getMetadata() throws KeyczarException {
return METADATA;
}
};
KeyczarPBEReader encrypted = new KeyczarPBEReader(staticReader, PASSPHRASE);
String prefix = "{\"aesKeyString\":\"oThFEDqkkLyp80hhh1QFjA\"";
assertEquals(prefix, encrypted.getKey().substring(0, prefix.length()));
GenericKeyczar keyczar = new GenericKeyczar(encrypted);
assertEquals(1, keyczar.getVersions().size());
}
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:28,代码来源:KeyczarPBEReaderTest.java
示例19: testWriteReadSymmetricKey
import org.keyczar.exceptions.KeyczarException; //导入依赖的package包/类
@Test
public void testWriteReadSymmetricKey() throws KeyczarException {
GenericKeyczar keyczar = Util.createKey(DefaultKeyType.AES, KeyPurpose.DECRYPT_AND_ENCRYPT);
String path = tempFolder.getRoot().getAbsolutePath() + "/out.json";
Util.writeJsonToPath(keyczar, path);
Crypter roundtripped = new Crypter(Util.readJsonFromPath(path));
verifyKeyCompatibility(keyczar, roundtripped);
}
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:11,代码来源:UtilTest.java
示例20: initSign
import org.keyczar.exceptions.KeyczarException; //导入依赖的package包/类
public final void initSign()
throws KeyczarException
{
try
{
this.signature.initSign(RsaPrivateKey.this.jcePrivateKey);
return;
}
catch (GeneralSecurityException localGeneralSecurityException)
{
throw new KeyczarException(localGeneralSecurityException);
}
}
开发者ID:ChiangC,项目名称:FMTech,代码行数:14,代码来源:RsaPrivateKey.java
注:本文中的org.keyczar.exceptions.KeyczarException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论