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


Java SealedObject类代码示例

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


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

示例1: encrypt

import javax.crypto.SealedObject; //导入依赖的package包/类
/**
 * Encrypt a properties if the data definition (model-specific) requires it.
 * 
 * @param propertyQName             the property qualified name
 * @param inbound                   the property to encrypt
 * @return                          the encrypted property or the original if encryption is not required
 */
public Serializable encrypt(QName propertyQName, Serializable inbound)
{
    PropertyDefinition propertyDef = dictionaryService.getProperty(propertyQName);
    if (inbound == null || propertyDef == null || !(propertyDef.getDataType().getName().equals(DataTypeDefinition.ENCRYPTED)))
    {
        return inbound;
    }
    if (inbound instanceof SealedObject)
    {
        return inbound;
    }
    Serializable outbound = encryptor.sealObject(KeyProvider.ALIAS_METADATA, null, inbound);
    // Done
    return outbound;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:23,代码来源:MetadataEncryptor.java

示例2: decrypt

import javax.crypto.SealedObject; //导入依赖的package包/类
/**
 * Decrypt a property if the data definition (model-specific) requires it.
 * 
 * @param propertyQName             the property qualified name
 * @param inbound                   the property to decrypt
 * @return                          the decrypted property or the original if it wasn't encrypted
 */
public Serializable decrypt(QName propertyQName, Serializable inbound)
{
    PropertyDefinition propertyDef = dictionaryService.getProperty(propertyQName);
    if (inbound == null || propertyDef == null || !(propertyDef.getDataType().getName().equals(DataTypeDefinition.ENCRYPTED)))
    {
        return inbound;
    }
    if (!(inbound instanceof SealedObject))
    {
        return inbound;
    }
    try
    {
     Serializable outbound = encryptor.unsealObject(KeyProvider.ALIAS_METADATA, inbound);
     // Done
     return outbound;
    }
    catch(KeyException e)
    {
    	throw new AlfrescoRuntimeException("Invalid metadata decryption key", e);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:30,代码来源:MetadataEncryptor.java

示例3: convert

import javax.crypto.SealedObject; //导入依赖的package包/类
@Override
Serializable convert(Serializable value)
{
    if (value == null)
    {
        return null;
    }
    else if (value instanceof SealedObject)
    {
        return value;
    }
    else
    {
        throw new IllegalArgumentException("Encrypted properties must be encrypted by the client.");
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:17,代码来源:NodePropertyValue.java

示例4: sealObject

import javax.crypto.SealedObject; //导入依赖的package包/类
@Override
public Serializable sealObject(String keyAlias, AlgorithmParameters params, Serializable input)
{
    if (input == null)
    {
        return null;
    }
    Cipher cipher = getCipher(keyAlias, params, Cipher.ENCRYPT_MODE);
    if (cipher == null)
    {
        return input;
    }
    try
    {
        return new SealedObject(input, cipher);
    }
    catch (Exception e)
    {
        throw new AlfrescoRuntimeException("Failed to seal object", e);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-core,代码行数:22,代码来源:AbstractEncryptor.java

示例5: seal

import javax.crypto.SealedObject; //导入依赖的package包/类
/**
 * Seals the given cleartext key, using the password provided at
 * construction time
 */
SealedObject seal(Key key)
    throws Exception
{
    // create a random salt (8 bytes)
    byte[] salt = new byte[8];
    SunJCE.getRandom().nextBytes(salt);

    // create PBE parameters from salt and iteration count
    PBEParameterSpec pbeSpec = new PBEParameterSpec(salt, 20);

    // create PBE key from password
    PBEKeySpec pbeKeySpec = new PBEKeySpec(this.password);
    SecretKey sKey = new PBEKey(pbeKeySpec, "PBEWithMD5AndTripleDES");
    pbeKeySpec.clearPassword();

    // seal key
    Cipher cipher;

    PBEWithMD5AndTripleDESCipher cipherSpi;
    cipherSpi = new PBEWithMD5AndTripleDESCipher();
    cipher = new CipherForKeyProtector(cipherSpi, SunJCE.getInstance(),
                                       "PBEWithMD5AndTripleDES");
    cipher.init(Cipher.ENCRYPT_MODE, sKey, pbeSpec);
    return new SealedObjectForKeyProtector(key, cipher);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:KeyProtector.java

示例6: seal

import javax.crypto.SealedObject; //导入依赖的package包/类
/**
 * Seals the given cleartext key, using the password provided at
 * construction time
 */
SealedObject seal(Key key)
    throws Exception
{
    // create a random salt (8 bytes)
    byte[] salt = new byte[8];
    SunJCE.getRandom().nextBytes(salt);

    // create PBE parameters from salt and iteration count
    PBEParameterSpec pbeSpec = new PBEParameterSpec(salt, ITERATION_COUNT);

    // create PBE key from password
    PBEKeySpec pbeKeySpec = new PBEKeySpec(this.password);
    SecretKey sKey = new PBEKey(pbeKeySpec, "PBEWithMD5AndTripleDES");
    pbeKeySpec.clearPassword();

    // seal key
    Cipher cipher;

    PBEWithMD5AndTripleDESCipher cipherSpi;
    cipherSpi = new PBEWithMD5AndTripleDESCipher();
    cipher = new CipherForKeyProtector(cipherSpi, SunJCE.getInstance(),
                                       "PBEWithMD5AndTripleDES");
    cipher.init(Cipher.ENCRYPT_MODE, sKey, pbeSpec);
    return new SealedObjectForKeyProtector(key, cipher);
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:30,代码来源:KeyProtector.java

示例7: encryptAndSerializeObject

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

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

        try {
            final Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
            cipher.init(Cipher.ENCRYPT_MODE, key);
            final SealedObject sealedobject = new SealedObject(object, cipher);
            final ByteArrayOutputStream bos = new ByteArrayOutputStream();
            final ObjectOutputStream out = new ObjectOutputStream(bos);
            out.writeObject(sealedobject);
            final byte[] bytes = bos.toByteArray();
            return BaseEncoding.base64().encode(bytes);
        } catch (final Exception e) {
            log.error(e.toString(), e);
            throw new ElasticsearchException(e.toString());
        }
    }
 
开发者ID:petalmd,项目名称:armor,代码行数:21,代码来源:SecurityUtil.java

示例8: 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

示例9: encryptAndDecryptMessage

import javax.crypto.SealedObject; //导入依赖的package包/类
@Test
public void encryptAndDecryptMessage() throws Exception {
    MessageModel newMessage = new MessageModel(false, "OWNER", 1);


    PublicKey pubTest = Settings.getInstance().getPublicKey();
    PrivateKey privTest = Settings.getInstance().getPrivateKey();

    Log.d(LOG_TAG, "plain: " + newMessage.getOwnerName());

    SealedObject encrypted = Crypto.encryptBytes(newMessage, pubTest);
    assertNotNull("Encrypted SealedObject is null", encrypted);

    Object decrypted = Crypto.decryptBytes(encrypted, privTest);
    assertNotNull("Decrypted Object is null", decrypted);

    MessageModel oldMessage = (MessageModel) decrypted;
    assertEquals("Values before/after encryption don't match", oldMessage.getOwnerName(),
            "OWNER");
}
 
开发者ID:deshi-basara,项目名称:susurrus-android-app,代码行数:21,代码来源:CryptoTest.java

示例10: sealObject

import javax.crypto.SealedObject; //导入依赖的package包/类
public synchronized Object sealObject(Object object) throws CryptoException {
    try {
    	if (useSealedObject) {
    		return new SealedObject((Serializable)object, encryptCipher);
    	}
    	AccessibleByteArrayOutputStream baos = new AccessibleByteArrayOutputStream(1 << 13);
    	ObjectOutputStream oos = new ObjectOutputStream(baos);
    	oos.writeObject(object);
    	oos.flush();
    	oos.close();
    	return encrypt(baos.getBuffer(), 0, baos.getCount());
    } catch ( Exception e ) {
        try {
            initEncryptCipher();
        } catch (CryptoException err) {
            //shouldn't happen
        }
          throw new CryptoException(CorePlugin.Event.TEIID10013, CorePlugin.Util.gs(CorePlugin.Event.TEIID10013, e.getMessage()));
    }
}
 
开发者ID:kenweezy,项目名称:teiid,代码行数:21,代码来源:BasicCryptor.java

示例11: getContext

import javax.crypto.SealedObject; //导入依赖的package包/类
/**
 * Gets the security context from the exchange.
 * @param exchange the exchange
 * @param create create a new security context if one does not already exist in the exchange or if it is not still valid
 * @return the security context, or null if create is false and one didn't already exist or was not valid
 */
public SecurityContext getContext(Exchange exchange, boolean create) {
    SecurityContext securityContext = null;
    Property property = exchange.getContext().getProperty(EXCHANGE_PROPERTY, Scope.EXCHANGE);
    if (property != null) {
        Object object = property.getValue();
        if (object instanceof SecurityContext) {
            securityContext = (SecurityContext)object;
        } else if (object instanceof SealedObject) {
            PrivateCrypto privateCrypto = _systemSecurity.getPrivateCrypto();
            if (privateCrypto == null) {
                throw new IllegalStateException("privateCrypto == null");
            }
            securityContext = (SecurityContext)privateCrypto.unseal((SealedObject)object);
        } else if (object != null) {
            throw new IllegalArgumentException(object.getClass().getName() + " != " + EXCHANGE_PROPERTY);
        }
    }
    UUID systemUUID = _systemSecurity.getUUID();
    if ((securityContext == null || !securityContext.isValid(systemUUID)) && create) {
        Long timeoutMillis = _systemSecurity.getSecurityContextTimeoutMillis();
        securityContext = new DefaultSecurityContext(systemUUID, timeoutMillis);
    }
    return securityContext;
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:31,代码来源:SecurityContextManager.java

示例12: testReadObject

import javax.crypto.SealedObject; //导入依赖的package包/类
/**
 * readObject(ObjectInputStream s) method testing. Tests if the
 * serialization/deserialization works correctly: object is serialized,
 * deserialized, the content od deserialized object equals to the content of
 * initial object.
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "!Serialization",
    args = {}
)
public void testReadObject() throws Exception {
    String secret = "secret string";
    SealedObject so = new SealedObject(secret, new NullCipher());
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(bos);
    oos.writeObject(so);

    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(
            bos.toByteArray()));

    SealedObject so_des = (SealedObject) ois.readObject();
    assertEquals("The secret content of deserialized object "
            + "should be equal to the secret content of initial object",
            secret, so_des.getObject(new NullCipher()));
    assertEquals("The value returned by getAlgorithm() method of "
            + "deserialized object should be equal to the value returned "
            + "by getAlgorithm() method of initial object", so
            .getAlgorithm(), so_des.getAlgorithm());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:32,代码来源:SealedObjectTest.java

示例13: testGetAlgorithm

import javax.crypto.SealedObject; //导入依赖的package包/类
/**
 * getAlgorithm() method testing. Tests if the returned value equals to the
 * corresponding value of Cipher object.
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getAlgorithm",
    args = {}
)
public void testGetAlgorithm() throws Exception {
    String secret = "secret string";
    String algorithm = "DES";
    KeyGenerator kg = KeyGenerator.getInstance(algorithm);
    Key key = kg.generateKey();

    Cipher cipher = Cipher.getInstance(algorithm);
    cipher.init(Cipher.ENCRYPT_MODE, key);
    SealedObject so = new SealedObject(secret, cipher);

    assertEquals("The algorithm name should be the same as used "
            + "in cipher.", algorithm, so.getAlgorithm());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:24,代码来源:SealedObjectTest.java

示例14: seal

import javax.crypto.SealedObject; //导入依赖的package包/类
/**
 * Seals the given cleartext key, using the password provided at
 * construction time
 */
SealedObject seal(Key key)
    throws Exception
{
    // create a random salt (8 bytes)
    byte[] salt = new byte[8];
    SunJCE.RANDOM.nextBytes(salt);

    // create PBE parameters from salt and iteration count
    PBEParameterSpec pbeSpec = new PBEParameterSpec(salt, 20);

    // create PBE key from password
    PBEKeySpec pbeKeySpec = new PBEKeySpec(this.password);
    SecretKey sKey = new PBEKey(pbeKeySpec, "PBEWithMD5AndTripleDES");
    pbeKeySpec.clearPassword();

    // seal key
    Cipher cipher;

    PBEWithMD5AndTripleDESCipher cipherSpi;
    cipherSpi = new PBEWithMD5AndTripleDESCipher();
    cipher = new CipherForKeyProtector(cipherSpi, PROV,
                                       "PBEWithMD5AndTripleDES");
    cipher.init(Cipher.ENCRYPT_MODE, sKey, pbeSpec);
    return new SealedObjectForKeyProtector(key, cipher);
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:30,代码来源:KeyProtector.java

示例15: encryptAES

import javax.crypto.SealedObject; //导入依赖的package包/类
/** Encrypts the Serializable object with AES
    * @param plaintext the Serializable object to encrypt
    * @param password the password to use for encryption, if it's null or empty the default pass will be used instead
    * @return an encrypter String formatted as json containing the used cipher and the encrypted object
    */
   public static String encryptAES(Serializable plaintext, String password) {
	try{
		final PBEParameterSpec pbeParamSpec = new PBEParameterSpec(salt, 20);
		final PBEKeySpec pbeKeySpec = new PBEKeySpec( 
	    		(password==null || password.equalsIgnoreCase(""))?defaultPass:password.toCharArray()  );
		final SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance(AES_ALG);
		final SecretKey secretKey = secretKeyFactory.generateSecret(pbeKeySpec);

		final Cipher cipher = Cipher.getInstance(AES_ALG);
	    cipher.init(Cipher.ENCRYPT_MODE,secretKey,pbeParamSpec);

	    return gson.toJson(new SealedObject(plaintext,cipher));
	} catch(Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:uberspot,项目名称:Offline3fAuth,代码行数:23,代码来源:ObjCrypter.java


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