| @@ 1955-1983 (lines=29) @@ | ||
| 1952 | ||
| 1953 | // Now perform action on the file |
|
| 1954 | $err = ''; |
|
| 1955 | if ($type === 'decrypt') { |
|
| 1956 | try { |
|
| 1957 | \Defuse\Crypto\File::decryptFile( |
|
| 1958 | $source_file, |
|
| 1959 | $target_file, |
|
| 1960 | \Defuse\Crypto\Key::loadFromAsciiSafeString($ascii_key) |
|
| 1961 | ); |
|
| 1962 | } catch (Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) { |
|
| 1963 | $err = "decryption_not_possible"; |
|
| 1964 | } catch (Defuse\Crypto\Exception\EnvironmentIsBrokenException $ex) { |
|
| 1965 | $err = $ex; |
|
| 1966 | } catch (Defuse\Crypto\Exception\IOException $ex) { |
|
| 1967 | $err = $ex; |
|
| 1968 | } |
|
| 1969 | } elseif ($type === 'encrypt') { |
|
| 1970 | try { |
|
| 1971 | \Defuse\Crypto\File::encryptFile( |
|
| 1972 | $source_file, |
|
| 1973 | $target_file, |
|
| 1974 | \Defuse\Crypto\Key::loadFromAsciiSafeString($ascii_key) |
|
| 1975 | ); |
|
| 1976 | } catch (Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) { |
|
| 1977 | $err = "encryption_not_possible"; |
|
| 1978 | } catch (Defuse\Crypto\Exception\EnvironmentIsBrokenException $ex) { |
|
| 1979 | $err = $ex; |
|
| 1980 | } catch (Defuse\Crypto\Exception\IOException $ex) { |
|
| 1981 | $err = $ex; |
|
| 1982 | } |
|
| 1983 | } |
|
| 1984 | } else { |
|
| 1985 | /* |
|
| 1986 | File encryption/decryption is done with special password and not the SALTKEY |
|
| @@ 1990-2018 (lines=29) @@ | ||
| 1987 | */ |
|
| 1988 | ||
| 1989 | $err = ''; |
|
| 1990 | if ($type === 'decrypt') { |
|
| 1991 | try { |
|
| 1992 | \Defuse\Crypto\File::decryptFileWithPassword( |
|
| 1993 | $source_file, |
|
| 1994 | $target_file, |
|
| 1995 | $password |
|
| 1996 | ); |
|
| 1997 | } catch (Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) { |
|
| 1998 | $err = "wrong_key"; |
|
| 1999 | } catch (Defuse\Crypto\Exception\EnvironmentIsBrokenException $ex) { |
|
| 2000 | $err = $ex; |
|
| 2001 | } catch (Defuse\Crypto\Exception\IOException $ex) { |
|
| 2002 | $err = $ex; |
|
| 2003 | } |
|
| 2004 | } elseif ($type === 'encrypt') { |
|
| 2005 | try { |
|
| 2006 | \Defuse\Crypto\File::encryptFileWithPassword( |
|
| 2007 | $source_file, |
|
| 2008 | $target_file, |
|
| 2009 | $password |
|
| 2010 | ); |
|
| 2011 | } catch (Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) { |
|
| 2012 | $err = "wrong_key"; |
|
| 2013 | } catch (Defuse\Crypto\Exception\EnvironmentIsBrokenException $ex) { |
|
| 2014 | $err = $ex; |
|
| 2015 | } catch (Defuse\Crypto\Exception\IOException $ex) { |
|
| 2016 | $err = $ex; |
|
| 2017 | } |
|
| 2018 | } |
|
| 2019 | } |
|
| 2020 | ||
| 2021 | // return error |
|