Exemplo n.º 1
0
 private Properties decryptPwd(Properties initProps) {
   String encryptionKey = initProps.getProperty("encryptKeyFile");
   if (initProps.getProperty("password") != null && encryptionKey != null) {
     // this means the password is encrypted and use the file to decode it
     try {
       try (Reader fr = new InputStreamReader(new FileInputStream(encryptionKey), UTF_8)) {
         char[] chars = new char[100]; // max 100 char password
         int len = fr.read(chars);
         if (len < 6)
           throw new DataImportHandlerException(
               SEVERE, "There should be a password of length 6 atleast " + encryptionKey);
         Properties props = new Properties();
         props.putAll(initProps);
         String password = null;
         try {
           password =
               CryptoKeys.decodeAES(initProps.getProperty("password"), new String(chars, 0, len))
                   .trim();
         } catch (SolrException se) {
           throw new DataImportHandlerException(SEVERE, "Error decoding password", se.getCause());
         }
         props.put("password", password);
         initProps = props;
       }
     } catch (IOException e) {
       throw new DataImportHandlerException(
           SEVERE, "Could not load encryptKeyFile  " + encryptionKey);
     }
   }
   return initProps;
 }
Exemplo n.º 2
0
  /** Try with all signatures and return the name of the signature that matched */
  public String verify(String sig, ByteBuffer data) {
    exception = null;
    for (Map.Entry<String, PublicKey> entry : keys.entrySet()) {
      boolean verified;
      try {
        verified = CryptoKeys.verify(entry.getValue(), Base64.base64ToByteArray(sig), data);
        log.info("verified {} ", verified);
        if (verified) return entry.getKey();
      } catch (Exception e) {
        exception = e;
        log.info("NOT verified  ");
      }
    }

    return null;
  }