Examples of IEncryptionProvider


Examples of net.sourceforge.javautil.common.encryption.IEncryptionProvider

 
  @PrePersist @PreUpdate
  public <T> void encrypt (T entity) { this.encrypt(entity, ClassCache.getFor((Class<T>)entity.getClass())); }
 
  protected <T> void encrypt (T entity, ClassDescriptor<T> desc) {
    IEncryptionProvider provider = this.getProvider(desc, entity);
    this.encrypt(entity, desc, provider);
  }
View Full Code Here

Examples of net.sourceforge.javautil.common.encryption.IEncryptionProvider

  @PostLoad public <T> void decrypt (T entity) {
    this.decrypt(entity, ClassCache.getFor((Class<T>)entity.getClass()));
  }
 
  protected <T> void decrypt (T entity, ClassDescriptor<T> desc) {
    IEncryptionProvider provider = this.getProvider(desc, entity);
    this.decrypt(entity, desc, provider);
  }
View Full Code Here

Examples of net.sourceforge.javautil.common.encryption.IEncryptionProvider

    }
  }
 
  private <T> IEncryptionProvider getProvider (ClassDescriptor<T> clazz, T instance) {
    if (cache.containsKey(clazz.getDescribedClass().getName())) {
      IEncryptionProvider provider = cache.get(clazz.getDescribedClass().getName()).get();
      if (provider != null) return provider;
    }
   
    EncryptionConfig config = clazz.getAnnotation(EncryptionConfig.class);
    byte[] key = null;
    if (config != null && config.source() == Source.PASSWORD_LOCKER) {
      if ("".equals( config.sourceName() )) throw new IllegalArgumentException("Password locker source name must be provider for: " + clazz);
      if (PasswordContext.get() == null) throw new IllegalStateException("No password locker available for the current context");
     
      IPassword pw = PasswordContext.get().getPassword(config.sourceName());
      if (pw == null) throw new IllegalArgumentException("No such password in current context locker: " + config.sourceName());
     
      key = pw.getPassword();
    } else {
      ClassProperty property = clazz.getProperty(EncryptionKey.class);
      if (property == null) throw new IllegalStateException("No encryption key property available for: " + clazz);
     
      key = ReflectionUtil.coerce(byte[].class, property.getValue(instance));
    }
   
    try {
      IEncryptionProvider provider = new SimpleEncryptionProvider(SimpleEncryptionKey.createUsing(Strength.STRONG, config == null ? "AES" : config.algorithm(), key));
      cache.put(clazz.getDescribedClass().getName(), new SoftReference<IEncryptionProvider>(provider));
      return provider;
    } catch (InvalidKeyException e) {
      throw ThrowableManagerRegistry.caught(e);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.