免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3395 | 回复: 5
打印 上一主题 下一主题

[FreeBSD] OpenSSL (md5sum sha1sum cksum) 文件加密 [复制链接]

论坛徽章:
13
15-16赛季CBA联赛之同曦
日期:2016-01-28 19:52:032015亚冠之北京国安
日期:2015-10-07 14:28:19NBA常规赛纪念章
日期:2015-05-04 22:32:03处女座
日期:2015-01-15 19:45:44卯兔
日期:2014-10-28 16:17:14白羊座
日期:2014-05-24 15:10:46寅虎
日期:2014-05-10 09:50:35白羊座
日期:2014-03-12 20:52:17午马
日期:2014-03-01 08:37:27射手座
日期:2014-02-19 19:26:54子鼠
日期:2013-11-30 09:03:56狮子座
日期:2013-09-08 08:37:52
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-07-10 08:06 |只看该作者 |倒序浏览
本帖最后由 ulovko 于 2012-07-10 08:06 编辑

# display currently version
  1. openssl version
复制代码
# openssl list-message-digest-commands
  1. openssl dgst -sha1 file #(sha1,md5 etc.)
  2. openssl md5 < file  <==>  md5sum file
  3. openssl sha1 < file <==>  sha1sum file
复制代码
# openssl list-cipher-commands
  1. man openssl >> to see more details about enc ==> man enc <== u can see more!
复制代码
# asn1parse(1), ca(1), config(5), crl(1), crl2pkcs7(1), dgst(1),
# dhparam(1), dsa(1), dsaparam(1), enc(1), gendsa(1), genrsa(1), nseq(1),
# openssl(1), passwd(1), pkcs12(1), pkcs7(1), pkcs8(1), rand(1), req(1),
# rsa(1), rsautl(1), s_client(1), s_server(1), s_time(1),
# smime(1),spkac(1), verify(1), version(1), x509(1), crypto(3),ssl(3)

# To encrypt a file named file.txt with a password, using triple DES in CBC
# mode,stored base64 encoded:
  1. openssl enc -des3 -e -a -salt -in file.txt -out file.des3
复制代码
# To decrypt the resulting file.des3 file:
  1. openssl enc -des3 -d -a -salt -in file.des3 -out file.txt
复制代码
#EXAMPLES:
#Just base64 encode a binary file:
  1. openssl base64 -in file.bin -out file.b64
复制代码
#Decode the same file:
  1. openssl base64 -d -in file.b64 -out file.bin
复制代码
#Encrypt a file using triple DES in CBC mode using a prompted password:
  1. openssl des3 -salt -in file.txt -out file.des3
复制代码
#Decrypt a file using a supplied password:
  1. openssl des3 -d -salt -in file.des3 -out file.txt -k mypassword
复制代码
#Encrypt a file then base64 encode it (so it can be sent via mail for  example) using Blowfish in CBC mode:
  1. openssl bf -a -salt -in file.txt -out file.bf
复制代码
#Base64 decode a file then decrypt it:
  1. openssl bf -d -salt -a -in file.bf -out file.txt
复制代码
FROM: http://blog.chinaunix.net/uid-25256412-id-91486.html

论坛徽章:
89
水瓶座
日期:2014-04-01 08:53:31天蝎座
日期:2014-04-01 08:53:53天秤座
日期:2014-04-01 08:54:02射手座
日期:2014-04-01 08:54:15子鼠
日期:2014-04-01 08:55:35辰龙
日期:2014-04-01 08:56:36未羊
日期:2014-04-01 08:56:27戌狗
日期:2014-04-01 08:56:13亥猪
日期:2014-04-01 08:56:02亥猪
日期:2014-04-08 08:38:58程序设计版块每日发帖之星
日期:2016-01-05 06:20:00程序设计版块每日发帖之星
日期:2016-01-07 06:20:00
2 [报告]
发表于 2012-07-10 08:11 |只看该作者
好久以前用过gnupg来加密邮件和文件,不过后来没怎么用过。

论坛徽章:
13
15-16赛季CBA联赛之同曦
日期:2016-01-28 19:52:032015亚冠之北京国安
日期:2015-10-07 14:28:19NBA常规赛纪念章
日期:2015-05-04 22:32:03处女座
日期:2015-01-15 19:45:44卯兔
日期:2014-10-28 16:17:14白羊座
日期:2014-05-24 15:10:46寅虎
日期:2014-05-10 09:50:35白羊座
日期:2014-03-12 20:52:17午马
日期:2014-03-01 08:37:27射手座
日期:2014-02-19 19:26:54子鼠
日期:2013-11-30 09:03:56狮子座
日期:2013-09-08 08:37:52
3 [报告]
发表于 2012-07-10 08:13 |只看该作者
本帖最后由 ulovko 于 2012-07-10 08:14 编辑

回复 2# fender0107401

GPG (md5sum sha1sum cksum)

# Creating a key
  1. gpg --gen-key
复制代码
# Exporting keys
  1. gpg -o file.gpg --armor --export [UID]
复制代码
# Importing keys ==> when u received someone's pub key,u have to add them
# to your key database in order to be able to ues them.. ~/.gnupg/
  1. gpg --import [filename]
复制代码
# Revoke a key
  1. gpg --gen-revoke
复制代码
# Key administration
  1. gpg --list-keys
  2. gpg --list-sigs
  3. gpg --fingerprint
  4. gpg --list-secret-keys
  5. gpg --delete-key [UID]
  6. gpg --delete-secret-key
复制代码
# '?' to listing help
  1. gpg --edit-key [UID]
  2. Command> ?
  3. Command> revkey
  4. Do you really want to revoke this key? y
  5. Command> revsig
  6. Command> check
复制代码
# Signing and checking signatures
  1. gpg -o file.sig --sign file.txt
  2. gpg -o file.sig --clearsign file.txt
  3. gpg -o file.sig -ab file.txt
  4. gpg --verify file.sig file.txt
复制代码
# use '--version' to listing supported algorithms
  1. [root@ns1 ~]# gpg --version
  2. gpg (GnuPG) 1.4.5
  3. Copyright (C) 2006 Free Software Foundation, Inc.
  4. This program comes with ABSOLUTELY NO WARRANTY.
  5. This is free software, and you are welcome to redistribute it
  6. under certain conditions. See the file COPYING for details.

  7. Home: ~/.gnupg
  8. Supported algorithms:
  9. Pubkey: RSA, RSA-E, RSA-S, ELG-E, DSA
  10. Cipher: 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH
  11. Hash: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
  12. Compression: Uncompressed, ZIP, ZLIB, BZIP2
复制代码
# Encrypt and Decrypt
  1. gpg -o file.gpg -e -r jacky file.txt # use jacky's pubkey to encrypt 'file.txt'
  2. gpg -o file.txt -d file.gpg

  3. gpg -o file.asc -e --armor -r jacky file.txt
  4. gpg -o file.txt -d file.asc
复制代码
# symmetric encryption
  1. gpg -o file.gpg --cipher-algo 3des -c file.txt
  2. gpg -o file.txt -d file.gpg

  3. gpg -o file.asc --cipher-algo 3des --armor -c file.txt
  4. gpg -o file.txt -d file.asc
复制代码
# TIPS: (in E-mail transmission always select 'ASCII' file ~!Ooops..)
# ASCII file always use suffix '.asc'
# and Binary file always use '.gpg'


# Sample here:
  1. [root@ns1 home]# gpg --gen-key
  2. gpg (GnuPG) 1.4.5; Copyright (C) 2006 Free Software Foundation, Inc.
  3. This program comes with ABSOLUTELY NO WARRANTY.
  4. This is free software, and you are welcome to redistribute it
  5. under certain conditions. See the file COPYING for details.

  6. Please select what kind of key you want:
  7. (1) DSA and Elgamal (default)
  8. (2) DSA (sign only)
  9. (5) RSA (sign only)
  10. #Your selection?
  11. DSA keypair will have 1024 bits.
  12. ELG-E keys may be between 1024 and 4096 bits long.
  13. #What keysize do you want? (2048) 4096
  14. Requested keysize is 4096 bits
  15. Please specify how long the key should be valid.
  16. 0 = key does not expire
  17. <n>  = key expires in n days
  18. <n>w = key expires in n weeks
  19. <n>m = key expires in n months
  20. <n>y = key expires in n years
  21. #Key is valid for? (0) 1
  22. Key expires at Sun 11 Apr 2010
  23. 04:22:30 AM CST
  24. #Is this correct? (y/N) y

  25. You need a user ID to identify your
  26. key; the software constructs the user ID from the Real Name, Comment and  Email Address in this form: "Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>"

  27. #Real name: jacky
  28. #Email address: jacky@gmail.com
  29. #Comment: AK is a famous gun..
  30. You selected this USER-ID: "jacky (AK is a famous gun..) <jacky@gmail.com>"

  31. #Change (N)ame, (C)omment,(E)mail or (O)kay/(Q)uit? O
  32. #You need a Passphrase to protect your secret key.

  33. We need to generate a lot of random bytes. It is a good idea to perform  some
  34. other action (type on the keyboard, move the mouse, utilize the disks) during
  35. the prime generation; this gives the random number generator a better chance to
  36. gain enough entropy.
  37. +++++.++++++++++.++++++++++.++++++++++++++++++++.++++++++++++
  38. ++++++++++++++++++.+++++.+++++++++++++++.+++++..++++++++++++++
  39. +.+++++.+++++++++++++++......................+++++
  40. We need to generate a lot of random bytes. It is a good idea to perform  some
  41. other action (type on the keyboard, move the mouse, utilize the disks) during
  42. the prime generation; this gives the random number generator a better chance to
  43. gain enough entropy.
  44. +++++..+++++++++++++++.+++++++++++++++..++++++++++.+++++..+++++++
  45. +++.+++++++++++++++.++++++++++++++++++++.++++++++++++++++++++
  46. ++++++++++.+++++++++++++++++++++++++.+++++.+++++.+++++>+++++++
  47. ++++++++.+++++++++++++++.+++++.++++++++++......+++++>.+++++>...++++
  48. +>+++++..>.+++++...................................................>+++++............<.+++++......
  49. ...........................................................................+++++^^^
  50. gpg: key 58B2DE67 marked as ultimately trusted
  51. public and secret key created and signed.

  52. gpg: checking the trustdb
  53. gpg: 3 marginal(s) needed, 1
  54. complete(s) needed, PGP trust model
  55. gpg: depth: 0  valid:   2
  56. signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 2u
  57. gpg: next trustdb check due at 2010-04-10
  58. #pub   1024D/58B2DE67 2010-04-09 [expires:2010-04-10]
  59. # Key fingerprint = 59B5 0536 ACC1 94ED DA48 EE2E 9B98 D1C0 58B2 DE67
  60. # uid jacky (AK is a famous gun) <jacky@gmail.com>
  61. #sub   4096g/B41492A8 2010-04-09 [expires: 2010-04-10]
复制代码
FROM: http://blog.chinaunix.net/uid-25256412-id-91485.html

论坛徽章:
89
水瓶座
日期:2014-04-01 08:53:31天蝎座
日期:2014-04-01 08:53:53天秤座
日期:2014-04-01 08:54:02射手座
日期:2014-04-01 08:54:15子鼠
日期:2014-04-01 08:55:35辰龙
日期:2014-04-01 08:56:36未羊
日期:2014-04-01 08:56:27戌狗
日期:2014-04-01 08:56:13亥猪
日期:2014-04-01 08:56:02亥猪
日期:2014-04-08 08:38:58程序设计版块每日发帖之星
日期:2016-01-05 06:20:00程序设计版块每日发帖之星
日期:2016-01-07 06:20:00
4 [报告]
发表于 2012-07-10 08:14 |只看该作者
回复 3# ulovko

哈哈。

论坛徽章:
13
15-16赛季CBA联赛之同曦
日期:2016-01-28 19:52:032015亚冠之北京国安
日期:2015-10-07 14:28:19NBA常规赛纪念章
日期:2015-05-04 22:32:03处女座
日期:2015-01-15 19:45:44卯兔
日期:2014-10-28 16:17:14白羊座
日期:2014-05-24 15:10:46寅虎
日期:2014-05-10 09:50:35白羊座
日期:2014-03-12 20:52:17午马
日期:2014-03-01 08:37:27射手座
日期:2014-02-19 19:26:54子鼠
日期:2013-11-30 09:03:56狮子座
日期:2013-09-08 08:37:52
5 [报告]
发表于 2012-07-10 08:15 |只看该作者
小弟一直使用openssl作对称加密私密文件

论坛徽章:
0
6 [报告]
发表于 2012-07-10 21:40 |只看该作者
对称加密不安全的呀{:2_179:}
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP