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