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


Java SealedObject.getObject方法代码示例

本文整理汇总了Java中javax.crypto.SealedObject.getObject方法的典型用法代码示例。如果您正苦于以下问题:Java SealedObject.getObject方法的具体用法?Java SealedObject.getObject怎么用?Java SealedObject.getObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.crypto.SealedObject的用法示例。


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

示例1: decryptAnDeserializeObject

import javax.crypto.SealedObject; //导入方法依赖的package包/类
public static Serializable decryptAnDeserializeObject(final String string, final SecretKey key) {

        if (string == null) {
            throw new IllegalArgumentException("string must not be null");
        }

        try {
            final byte[] userr = BaseEncoding.base64().decode(string);
            final ByteArrayInputStream bis = new ByteArrayInputStream(userr);
            final ObjectInputStream in = new ObjectInputStream(bis);
            final SealedObject ud = (SealedObject) in.readObject();
            return (Serializable) ud.getObject(key);
        } catch (final Exception e) {
            log.error(e.toString(), e);
            throw new ElasticsearchException(e.toString());
        }
    }
 
开发者ID:petalmd,项目名称:armor,代码行数:18,代码来源:SecurityUtil.java

示例2: readFtpHistory

import javax.crypto.SealedObject; //导入方法依赖的package包/类
public Collection<Ftp> readFtpHistory(Cipher cipher, String intallationPath) {

		String path = intallationPath + "/" + FTP_FOLDER;
		File directory = new File(path);
		File[] subfiles = directory.listFiles();
		Collection<Ftp> ftps = new ArrayList<Ftp>();

		for (int i = 0; i < subfiles.length; i++) {
			try {
				String ftpPath = subfiles[i].getAbsolutePath();
				ObjectInputStream fRo = new ObjectInputStream(
						new GZIPInputStream(new FileInputStream(ftpPath)));
				SealedObject sealedObject = (SealedObject) fRo.readObject();
				Ftp ftp = (Ftp) sealedObject.getObject(cipher);
				ftps.add(ftp);
				fRo.close();
			} catch (Exception e) {
				// throw new LoadingException("Can't load ftp! " +
				// e.getMessage());
				e.printStackTrace();
			}
		}
		return ftps;
	}
 
开发者ID:dedmen,项目名称:LEA,代码行数:25,代码来源:FtpDAO.java

示例3: unsealObject

import javax.crypto.SealedObject; //导入方法依赖的package包/类
/**
 * Parses a SealedObject from the given byte array and retrieves the original wrapped object
 *
 * @param encryptedObject a byte array representing a SealedObject
 * @param maxBytes        the maximum size allowed for the read object
 * @return the original Serializable object
 * @throws CryptoOperationRuntimeException
 * @see #sealObject(java.io.Serializable) the matching wrapping operation
 */
public Object unsealObject(byte[] encryptedObject, long maxBytes) {
    try {
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(encryptedObject);
        SealedObject sealedObject = SafeObjectReader.safeReadObject(SealedObject.class, new ArrayList<>(), MAX_OBJECTS, maxBytes, byteArrayInputStream);
        return sealedObject.getObject(key);
    } catch (IOException | ClassNotFoundException | InvalidKeyException | NoSuchAlgorithmException e) {
        throw new CryptoOperationRuntimeException("cannot unseal object", e);
    }

}
 
开发者ID:republique-et-canton-de-geneve,项目名称:chvote-1-0,代码行数:20,代码来源:ObjectSealer.java

示例4: unseal

import javax.crypto.SealedObject; //导入方法依赖的package包/类
/**
 * Unseals the specified sealed object.
 * @param object the sealed object
 * @return the unsealed object
 */
public Serializable unseal(SealedObject object) {
    try {
        Cipher cipher = Cipher.getInstance(_sealAlgorithm);
        cipher.init(Cipher.DECRYPT_MODE, _secretKey);
        return (Serializable)object.getObject(cipher);
    } catch (Exception e) {
        throw new SwitchYardException(e);
    }
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:15,代码来源:PrivateCrypto.java

示例5: readPrivateKey

import javax.crypto.SealedObject; //导入方法依赖的package包/类
public final static PrivateKey readPrivateKey(Cipher decrypt_cipher, String key_file, String algorithm) throws IOException, ClassNotFoundException, GeneralSecurityException {
	URL key_url = PasswordKey.class.getResource("/" + key_file);
	ObjectInputStream is = new ObjectInputStream(key_url.openStream());
	SealedObject sealed_key = (SealedObject)is.readObject();
	byte[] encoded_registration_key = (byte[])sealed_key.getObject(decrypt_cipher);
	return KeyManager.readPrivateKey(encoded_registration_key, algorithm);
}
 
开发者ID:sunenielsen,项目名称:tribaltrouble,代码行数:8,代码来源:PasswordKey.java

示例6: testKey

import javax.crypto.SealedObject; //导入方法依赖的package包/类
static void testKey() throws Exception
{
   int size = 8 * 24;
   KeyGenerator kgen = KeyGenerator.getInstance("Blowfish");
   kgen.init(size);
   SecretKey key = kgen.generateKey();
   byte[] kbytes = key.getEncoded();
   System.out.println("key.Algorithm = "+key.getAlgorithm());
   System.out.println("key.Format = "+key.getFormat());
   System.out.println("key.Encoded Size = "+kbytes.length);
   
   Cipher cipher = Cipher.getInstance("Blowfish");
   AlgorithmParameters params = cipher.getParameters();
   System.out.println("Blowfish.params = "+params);
   cipher.init(Cipher.ENCRYPT_MODE, key);
   SealedObject msg = new SealedObject("This is a secret", cipher);
   
   SecretKeySpec serverKey = new SecretKeySpec(kbytes, "Blowfish");
   Cipher scipher = Cipher.getInstance("Blowfish");
   scipher.init(Cipher.DECRYPT_MODE, serverKey);
   String theMsg = (String) msg.getObject(scipher);
   System.out.println("Decrypted: "+theMsg);
   
   SecureRandom rnd = SecureRandom.getInstance("SHA1PRNG");
   BigInteger bi = new BigInteger(320, rnd);
   byte[] k2bytes = bi.toByteArray();
   SecretKeySpec keySpec = new SecretKeySpec(k2bytes, "Blowfish");
   System.out.println("key2.Algorithm = "+key.getAlgorithm());
   System.out.println("key2.Format = "+key.getFormat());
   System.out.println("key2.Encoded Size = "+kbytes.length);
   System.out.println("keySpec.Algorithm = " + keySpec.getAlgorithm());
   System.out.println("keySpec.Format = " + keySpec.getFormat());
}
 
开发者ID:picketbox,项目名称:picketbox,代码行数:34,代码来源:TestJCE.java

示例7: recieveKey

import javax.crypto.SealedObject; //导入方法依赖的package包/类
@Override
public PublicKey recieveKey() throws Exception {
    ObjectInputStream in = new ObjectInputStream(this.in);
    SealedObject encryptedKey = (SealedObject) in.readObject();
    return (PublicKey) encryptedKey.getObject(SecretKeyFactory.getInstance("DES").translateKey(new SecretKeySpec(b, "DES")));
    
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:8,代码来源:ServerDHKeyAgreement.java

示例8: test1

import javax.crypto.SealedObject; //导入方法依赖的package包/类
private boolean test1(Cipher c, Cipher d, String s) 
throws Exception 
{
    start = System.nanoTime();
    String rs = "";
    SealedObject so = new SealedObject(s, c);
    rs = (String)so.getObject(d);
    finish = System.nanoTime();
    return rs.equals(s);
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:11,代码来源:TestSealedObject.java

示例9: test2

import javax.crypto.SealedObject; //导入方法依赖的package包/类
private boolean test2(Cipher c, SecretKey sKey, String s)
throws Exception 
{
    start = System.nanoTime();
    String rs = "";
    SealedObject so = new SealedObject(s, c);
    rs = (String)so.getObject(sKey);
    finish = System.nanoTime();
    return rs.equals(s);
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:11,代码来源:TestSealedObject.java

示例10: readAutoConfig

import javax.crypto.SealedObject; //导入方法依赖的package包/类
public Ftp readAutoConfig(Cipher cipher, String path)
		throws FileNotFoundException, IOException, ClassNotFoundException,
		NoSuchAlgorithmException, NoSuchPaddingException,
		InvalidKeyException, IllegalBlockSizeException, BadPaddingException {

	ObjectInputStream fRo = new ObjectInputStream(new GZIPInputStream(
			new FileInputStream(path)));
	SealedObject sealedObject = (SealedObject) fRo.readObject();
	Ftp ftp = (Ftp) sealedObject.getObject(cipher);
	fRo.close();
	return ftp;
}
 
开发者ID:dedmen,项目名称:LEA,代码行数:13,代码来源:FtpDAO.java

示例11: runTest

import javax.crypto.SealedObject; //导入方法依赖的package包/类
public boolean runTest(Provider p, String algo, PrintStream out)
        throws Exception {

    byte[] salt = new byte[8];
    int ITERATION_COUNT = 1000;
    AlgorithmParameters pbeParams = null;

    String baseAlgo
            = new StringTokenizer(algo, "/").nextToken().toUpperCase();
    boolean isAES = baseAlgo.contains("AES");

    try {
        // Initialization
        Cipher ci = Cipher.getInstance(algo, p);
        new Random().nextBytes(salt);
        AlgorithmParameterSpec aps = new PBEParameterSpec(salt,
                ITERATION_COUNT);
        SecretKeyFactory skf = SecretKeyFactory.getInstance(baseAlgo, p);
        SecretKey key = skf.generateSecret(
                new PBEKeySpec("Secret Lover".toCharArray()));

        // Seal
        if (isAES) {
            ci.init(Cipher.ENCRYPT_MODE, key);
            pbeParams = ci.getParameters();
        } else {
            ci.init(Cipher.ENCRYPT_MODE, key, aps);
        }

        SealedObject so = new SealedObject(key, ci);

        // Unseal and compare
        if (isAES) {
            ci.init(Cipher.DECRYPT_MODE, key, pbeParams);
        } else {
            ci.init(Cipher.DECRYPT_MODE, key, aps);
        }

        SecretKey unsealedKey;

        unsealedKey = (SecretKey) so.getObject(ci);
        if (!Arrays.equals(unsealedKey.getEncoded(), key.getEncoded())) {
            return false;
        }

        unsealedKey = (SecretKey) so.getObject(key);
        if (!Arrays.equals(unsealedKey.getEncoded(), key.getEncoded())) {
            return false;
        }

        unsealedKey = (SecretKey) so.getObject(key, "SunJCE");
        return Arrays.equals(unsealedKey.getEncoded(), key.getEncoded());
    } catch (InvalidKeyException ex) {
        if (baseAlgo.endsWith("TRIPLEDES") || baseAlgo.endsWith("AES_256")) {
            out.println(
                    "Expected exception , keyStrength > 128 within" + algo);
            return true;
        }

        throw ex;
    }
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:63,代码来源:PBESealedObject.java

示例12: perform

import javax.crypto.SealedObject; //导入方法依赖的package包/类
public TestResult perform()
{
    try
    {
        KeyGenerator keyGen = KeyGenerator.getInstance("DES", provider);
        Key key = keyGen.generateKey();
        Cipher c = Cipher.getInstance("DES/ECB/PKCS5Padding", provider);

        c.init(Cipher.ENCRYPT_MODE, key);
        String object = "Hello world";
        SealedObject so = new SealedObject(object, c);
        c.init(Cipher.DECRYPT_MODE, key);

        Object o = so.getObject(c);
        if (!o.equals(object))
        {
            return new SimpleTestResult(false, "Result object 1 not equal"
                    + "orig: " + object + " res: " + o);
        }

        o = so.getObject(key);
        if (!o.equals(object))
        {
            return new SimpleTestResult(false, "Result object 2 not equal"
                    + "orig: " + object + " res: " + o);
        }

        o = so.getObject(key, provider);
        if (!o.equals(object))
        {
            return new SimpleTestResult(false, "Result object 3 not equal"
                    + "orig: " + object + " res: " + o);
        }

        return new SimpleTestResult(true, getName() + ": Okay");
    }
    catch (Exception e)
    {
        return new SimpleTestResult(false, getName()
                + ": failed excpetion - " + e.toString(), e);
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:43,代码来源:SealedTest.java


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