private String decrypt ( String value ) { Crypto crypto = new Crypto ( this ) ; String keyFile = System . getProperty ( Key . APPLICATION_PRIVATEKEY . toString ( ) ) ; if ( StringUtils . isNotBlank ( keyFile ) ) { try ( Stream < String > lines = Files . lines ( Paths . get ( keyFile ) ) ) { //NOSONAR KeyFile can intentionally come from user input String key = lines . findFirst ( ) . orElse ( null ) ; if ( StringUtils . isNotBlank ( key ) ) { PrivateKey privateKey = crypto . getPrivateKeyFromString ( key ) ; String cryptex = StringUtils . substringBetween ( value , CRYPTEX_TAG , "}" ) ; if ( privateKey != null && StringUtils . isNotBlank ( cryptex ) ) { return crypto . decrypt ( cryptex , privateKey ) ; } else { LOG . error ( "Failed to decrypt an encrypted config value" ) ; this . decrypted = false ; } } } catch ( IOException | SecurityException | MangooEncryptionException e ) { LOG . error ( "Failed to decrypt an encrypted config value" , e ) ; this . decrypted = false ; } } else { LOG . error ( "Found an encrypted value in config file but private key for decryption is missing" ) ; this . decrypted = false ; } return "" ; }
Decrypts a given property key and rewrites it to props