Najeebsk

OPENSSL.bat.txt

Feb 3rd, 2024
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.89 KB | None | 0 0
  1. To generate a random password
  2. openssl rand -base64 32
  3. To Encrypt File
  4. openssl enc -pbkdf2 -in "${file_name}" -out "${file_name}.enc" -md sha512 -salt -pass "pass:${my_password}"
  5. The decrypting command is almost similar to the encrypting command, with an additional -d flag, and output/input file names switched
  6. openssl enc -d -pbkdf2 -in "${file_name}.enc" -out "${file_name}" -md sha512 -salt -pass "pass:${my_password}"
  7. From version 1.1.1, -pbkdf2 or -iter cypher are recommended over -aes-256-cbc. If you are using openssl version older than 1.1.1,
  8. replace -pbkdf2 with -aes-256-cbc. Using -aes-256-cbc with openssl version newer or equal to 1.1.1 will emit the error:
  9. To check openssl version: openssl version
  10. OpenSSL 3.0.8 7 Feb 2023 (Library: OpenSSL 3.0.8 7 Feb 2023)
  11. If you have multiple files or a directory. There is one more step to combine these files into
  12. tar -Jcf "${file_name}.tar.xz" -C . "${dir_name}"
  13. Encrypt Files in Linux
  14. # tar -czf - * | openssl enc -e -aes256 -out secured.tar.gz
  15. Decrypt Files in Linux
  16. To decrypt a tar archive contents, use the following command.
  17. # openssl enc -d -aes256 -in secured.tar.gz | tar xz -C test
  18. Encrypt & Decrypt a single file
  19. openssl aes-256-cbc -a -salt -in img1.jpg -out img1.jpg.enc
  20. openssl aes-256-cbc -d -a -in img1.jpg.enc -out img1.jpg
  21. Encrypt & Decrypt multiple files within one directory
  22. =====================================================
  23. To encrypt all files in one folder with a password that you set form the command line
  24. for f in * ; do [ -f $f ] && openssl aes-256-cbc -a -salt -in $f -out $f.enc -k PASSWORD ; done
  25.  
  26. To encrypt all files in one folder with a password that you set in the file author.txt and then remove all the original JPG files and the author.txt file itself for obvious reasons!
  27. for f in * ; do [ -f $f ] && openssl aes-256-cbc -a -salt -in $f -out $f.enc -pass file:author.txt ; done ; rm *.JPG ; rm *.txt
  28. To encrypt all files in one folder with a password set in the command line and then erase the bash history and remove all tar files. We remove the bash history so that your password is not retrievable by simply pressing the up arrow key!
  29.  
  30. for f in * ; do [ -f $f ] && openssl aes-256-cbc -a -salt -in $f -out $f.enc -k PASSWORD ; done ; rm *.tar ; history -c && history -w
  31.  
  32. Encrypt & Decrypt all files recursively from parent directory
  33. =============================================================
  34. Encrypt all files recursively with a password set from the command line and then erase the bash history and remove all the original tar files.
  35. This assumes that the files to be encrypted are tar files, you can of course run the command on any type of file extension.
  36.  
  37. for f in **/*.tar ; do [ -f $f ] && openssl aes-256-cbc -a -salt -in $f -out $f.enc -k PASSWORD ; done ; rm **/*.tar ; history -c && history -w
  38. -------------------------------------------------------------------------------------------------------------------------
  39. Examples
  40. Delete the testfile if it is is 15 days old or older:
  41. forfiles /p "D:\CLI" /s /m *.* /D -15 /C "cmd /c del @path"
  42.  
  43. Delete the testfile if it is is 5 days old or older:
  44. C:\> forfiles /m testfile.txt /c "cmd /c Del testfile.txt " /d -5
  45.  
  46. Find all .xlsx files that were last modified 30 days ago or older:
  47. C:\> FORFILES /M *.xlsx /C "cmd /c echo @path was changed 30 days ago" /D -30
  48.  
  49. List the size of all .doc files:
  50. C:\> FORFILES /S /M *.doc /C "cmd /c echo @fsize"
  51.  
  52. Run a command against each text file newer than 1st Jan 2001:
  53. C:\> FORFILES /D +01/01/2021 /m *.txt /C "CMD /c echo @fname is new since Jan 1st 2021"
  54. FORFILES /D +01/01/2024 /m *.* /C "cmd /c del @path"
  55. FORFILES /P "D:\F" /S /D +01/01/2024 /M *.* /C "cmd /c del @path"
  56. FORFILES /P "D:\F" /S /D -01/01/2024 /M *.* /C "cmd /c del @path"
  57.  
  58. ----------------------------------------------------------------------------------------
  59. 3. Once you are in the correct directory, type the following command to change the creation date and time:
  60. copy /b filename +, , where "filename" is the name of the file you want to modify.
  61. 4. To change the modification date and time, use the following command:
  62. copy /b M.cmd +,,
  63. copy /b filename.ext +,,
  64. 5. To change the last access date and time, use the following command:
  65. copy /b filename +,,
  66. 6. Replace "filename" with the actual name of the file, and make sure to remove the "," symbols when using the commands.
  67. 7. Press Enter to execute the command. The file’s dates and times will be modified accordingly.
  68. ----------------------------------------------------------------------------------------------
  69. Here are the notes from the Power Shell .
  70.  
  71. DATE CREATED
  72. (Get-Item "PathToItem").CreationTime=("15 January 2022 10:00:00")
  73.  
  74. SAMPLE
  75. (Get-Item "D:\F\N\M.cmd").CreationTime=("15 January 2024 10:00:00")
  76.  
  77. -------------------------------------------------------------------------------
  78.  
  79. DATE MODIFIED
  80. (Get-Item "PathToItem").LastWriteTime=("16 January 2022 11:00:00")
  81.  
  82. SAMPLE
  83. (Get-Item "D:\F\N\M.cmd").LastWriteTime=("16 January 2024 11:00:00")
  84.  
  85. -------------------------------------------------------------------------------
  86.  
  87. DATE ACCESSED
  88. (Get-Item "PathToItem").LastAccessTime=("17 January 2022 12:00:00")
  89.  
  90. SAMPLE
  91. (Get-Item "C:\demo\File3.txt").LastAccessTime=("17 January 2022 12:00:00")
  92.  
  93. -------------------------------------------------------------------------------
  94.  
  95. If date accessed is not changing then run
  96. fsutil behavior set disablelastaccess 0
  97.  
  98. -------------------------------------------------------------------------------
  99.  
  100. CHANGE ATTRIBUTES FOR ALL FILES IN A FOLDER
  101. Get-ChildItem -force PathToItem * | ForEach-Object{$_.CreationTime = ("15 January 2022 10:00:00")}
  102. Get-ChildItem -force PathToItem * | ForEach-Object{$_.LastWriteTime = ("15 January 2022 10:00:00")}
  103. Get-ChildItem -force PathToItem * | ForEach-Object{$_.LastAccessTime = ("15 January 2022 10:00:00")}
  104.  
  105. SAMPLE
  106. Get-ChildItem -force C:\demo\Folder1 * | ForEach-Object{$_.CreationTime = ("15 January 2022 10:00:00")}
Add Comment
Please, Sign In to add comment