| @@ 1927-1955 (lines=29) @@ | ||
| 1924 | ||
| 1925 | // Now perform action on the file |
|
| 1926 | $err = ''; |
|
| 1927 | if ($type === 'decrypt') { |
|
| 1928 | try { |
|
| 1929 | \Defuse\Crypto\File::decryptFile( |
|
| 1930 | $source_file, |
|
| 1931 | $target_file, |
|
| 1932 | \Defuse\Crypto\Key::loadFromAsciiSafeString($ascii_key) |
|
| 1933 | ); |
|
| 1934 | } catch (Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) { |
|
| 1935 | $err = "decryption_not_possible"; |
|
| 1936 | } catch (Defuse\Crypto\Exception\EnvironmentIsBrokenException $ex) { |
|
| 1937 | $err = $ex; |
|
| 1938 | } catch (Defuse\Crypto\Exception\IOException $ex) { |
|
| 1939 | $err = $ex; |
|
| 1940 | } |
|
| 1941 | } elseif ($type === 'encrypt') { |
|
| 1942 | try { |
|
| 1943 | \Defuse\Crypto\File::encryptFile( |
|
| 1944 | $source_file, |
|
| 1945 | $target_file, |
|
| 1946 | \Defuse\Crypto\Key::loadFromAsciiSafeString($ascii_key) |
|
| 1947 | ); |
|
| 1948 | } catch (Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) { |
|
| 1949 | $err = "encryption_not_possible"; |
|
| 1950 | } catch (Defuse\Crypto\Exception\EnvironmentIsBrokenException $ex) { |
|
| 1951 | $err = $ex; |
|
| 1952 | } catch (Defuse\Crypto\Exception\IOException $ex) { |
|
| 1953 | $err = $ex; |
|
| 1954 | } |
|
| 1955 | } |
|
| 1956 | } else { |
|
| 1957 | /* |
|
| 1958 | File encryption/decryption is done with special password and not the SALTKEY |
|
| @@ 1962-1990 (lines=29) @@ | ||
| 1959 | */ |
|
| 1960 | ||
| 1961 | $err = ''; |
|
| 1962 | if ($type === 'decrypt') { |
|
| 1963 | try { |
|
| 1964 | \Defuse\Crypto\File::decryptFileWithPassword( |
|
| 1965 | $source_file, |
|
| 1966 | $target_file, |
|
| 1967 | $password |
|
| 1968 | ); |
|
| 1969 | } catch (Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) { |
|
| 1970 | $err = "wrong_key"; |
|
| 1971 | } catch (Defuse\Crypto\Exception\EnvironmentIsBrokenException $ex) { |
|
| 1972 | $err = $ex; |
|
| 1973 | } catch (Defuse\Crypto\Exception\IOException $ex) { |
|
| 1974 | $err = $ex; |
|
| 1975 | } |
|
| 1976 | } elseif ($type === 'encrypt') { |
|
| 1977 | try { |
|
| 1978 | \Defuse\Crypto\File::encryptFileWithPassword( |
|
| 1979 | $source_file, |
|
| 1980 | $target_file, |
|
| 1981 | $password |
|
| 1982 | ); |
|
| 1983 | } catch (Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) { |
|
| 1984 | $err = "wrong_key"; |
|
| 1985 | } catch (Defuse\Crypto\Exception\EnvironmentIsBrokenException $ex) { |
|
| 1986 | $err = $ex; |
|
| 1987 | } catch (Defuse\Crypto\Exception\IOException $ex) { |
|
| 1988 | $err = $ex; |
|
| 1989 | } |
|
| 1990 | } |
|
| 1991 | } |
|
| 1992 | ||
| 1993 | // return error |
|