| @@ 1885-1913 (lines=29) @@ | ||
| 1882 | ||
| 1883 | // Now perform action on the file |
|
| 1884 | $err = ''; |
|
| 1885 | if ($type === 'decrypt') { |
|
| 1886 | try { |
|
| 1887 | \Defuse\Crypto\File::decryptFile( |
|
| 1888 | $source_file, |
|
| 1889 | $target_file, |
|
| 1890 | \Defuse\Crypto\Key::loadFromAsciiSafeString($ascii_key) |
|
| 1891 | ); |
|
| 1892 | } catch (Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) { |
|
| 1893 | $err = "decryption_not_possible"; |
|
| 1894 | } catch (Defuse\Crypto\Exception\EnvironmentIsBrokenException $ex) { |
|
| 1895 | $err = $ex; |
|
| 1896 | } catch (Defuse\Crypto\Exception\IOException $ex) { |
|
| 1897 | $err = $ex; |
|
| 1898 | } |
|
| 1899 | } elseif ($type === 'encrypt') { |
|
| 1900 | try { |
|
| 1901 | \Defuse\Crypto\File::encryptFile( |
|
| 1902 | $source_file, |
|
| 1903 | $target_file, |
|
| 1904 | \Defuse\Crypto\Key::loadFromAsciiSafeString($ascii_key) |
|
| 1905 | ); |
|
| 1906 | } catch (Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) { |
|
| 1907 | $err = "encryption_not_possible"; |
|
| 1908 | } catch (Defuse\Crypto\Exception\EnvironmentIsBrokenException $ex) { |
|
| 1909 | $err = $ex; |
|
| 1910 | } catch (Defuse\Crypto\Exception\IOException $ex) { |
|
| 1911 | $err = $ex; |
|
| 1912 | } |
|
| 1913 | } |
|
| 1914 | } else { |
|
| 1915 | /* |
|
| 1916 | File encryption/decryption is done with special password and not the SALTKEY |
|
| @@ 1920-1948 (lines=29) @@ | ||
| 1917 | */ |
|
| 1918 | ||
| 1919 | $err = ''; |
|
| 1920 | if ($type === 'decrypt') { |
|
| 1921 | try { |
|
| 1922 | \Defuse\Crypto\File::decryptFileWithPassword( |
|
| 1923 | $source_file, |
|
| 1924 | $target_file, |
|
| 1925 | $password |
|
| 1926 | ); |
|
| 1927 | } catch (Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) { |
|
| 1928 | $err = "wrong_key"; |
|
| 1929 | } catch (Defuse\Crypto\Exception\EnvironmentIsBrokenException $ex) { |
|
| 1930 | $err = $ex; |
|
| 1931 | } catch (Defuse\Crypto\Exception\IOException $ex) { |
|
| 1932 | $err = $ex; |
|
| 1933 | } |
|
| 1934 | } elseif ($type === 'encrypt') { |
|
| 1935 | try { |
|
| 1936 | \Defuse\Crypto\File::encryptFileWithPassword( |
|
| 1937 | $source_file, |
|
| 1938 | $target_file, |
|
| 1939 | $password |
|
| 1940 | ); |
|
| 1941 | } catch (Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) { |
|
| 1942 | $err = "wrong_key"; |
|
| 1943 | } catch (Defuse\Crypto\Exception\EnvironmentIsBrokenException $ex) { |
|
| 1944 | $err = $ex; |
|
| 1945 | } catch (Defuse\Crypto\Exception\IOException $ex) { |
|
| 1946 | $err = $ex; |
|
| 1947 | } |
|
| 1948 | } |
|
| 1949 | } |
|
| 1950 | ||
| 1951 | // return error |
|