OpenSSL encryption and decryption

Source: Internet
Author: User

I. Preface

OpenSSL is an open-source software library package that implements SSL and TLS protocols. Its main library is written in C language and implements basic encryption functions.

OpenSSL can run on most Unix-like operating systems (including Solaris, Linux, Mac OS X, and various open-source BSD operating systems), OpenVMS, and Microsoft Windows. It also provides a portable version that can run on IBM I (OS/400.

OpenSSL consists of three parts: libcryto, a general-purpose encryption library, which implements a large number of encryption libraries, libssl, and SSL. is used to implement TLS/SSL functions, OpenSSL is the third, is a multi-functional command line tool, it can implement encryption and decryption, and even can be used as a ca, you can create a certificate, revoke the certificate.

Ii. Encryption type:

There are two types of encryption: symmetric encryption and asymmetric encryption.

Here we mainly study asymmetric encryption:

[[Email protected] ~] # Cp/etc/fstab./# copy the file to the current directory [[email protected] ~] # Lsanaconda-ks.cfg fstab install. Log install. log. syslog [[email protected] ~] # Cat fstab # view the file #/etc/fstab # Created by Anaconda on Fri Dec 26 18:09:56 2014 # accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab (5), findfs (8), Mount (8) and/or blkid (8) for more info #/dev/mapper/vg_magine3562-lv_root/ext4 defaults 1 1 UUID = d507dc4f-dcaa-4311-9aa6-3392322b064c/boot ext4 defaults 1 2/dev/mapper/vg_magine3562-lv_home/home ext4 defaults 1 2/dev/mapper/vg_magine3562-lv_swap swap defaults 0 0 tmpfs/dev/SHM tmpfs defaults 0 0 devpts/dev/PTS devpts gid = 5, mode = 620 0 0 sysfs/sys sysfs defaults 0 0 proc/proc defaults 0 0 [[email protected] ~] # OpenSSL ENC-des3-In fstab-e-out fstab. des3 # encryption enter des-ede3-cbc encryption password: # encryption password verifying-enter des-ede3-cbc encryption password: # enter the password again [[email protected] ~] # The lsanaconda-ks.cfg fstab. des3 install. Log install. log. syslog [[email protected] ~] # Cat fstab. des3 # view the encrypted file. O... frame. M. K folder ??.? [?? .?. JD play y? Limit two E19 ?)?. Shan ai +? Poly. ug? Zieh ??!.?? G? Y? 6? Q % [email protected]?. Z .. g problems .? Usage: c ..? Commission-?]?. M | .?? Wrong ov .?.. '{.#!? E <[^? * 2 ??. C %4gs % ??? /C> MX5 ??. Ray P? Q ??. Q0te now Q. Is there a bowl of benzene ?? H'tx Jun 8.-s .??.?. Cr! Why? Yi. Q ?.? Z. o6 ?. V ?? W. (too many .;.?? 9? U]?. Why J ?. & U ?? {] O2 ?? I. _ Shuai omitted X ...? A maximum capacity ???. B ,?.. 7 P & H error ?? Q. I *? ".?. UGU 6 .?? V <?. G? G? [+ Sans G? + FN ??.?. Division 9m. g. P ??? "?}? Lian \ Jian K ..??? Cluster -? Q... y .....? E]? S... 1? E. W ?.?.? Rt. ^? V ?. Comment 'U splash ..:.?? Town ?.. Ray! 8? Forbidden. F? :?..?? Wzi ??? Q? Export k5wjk4 .?. La # | = p4jw ?? Tw ?? FD .?).? "?? 5. loose? Listen 7? Why? MX? Zaj + S labels \ vmv0 .??. Why? J? :?.. R .?. Q? V Jin ..? M role? Hkm? B? Parent. {. Role <?. Jue. _ gang _ [[email protected] ~] # OpenSSL ENC-des3-In fstab. des3-D-out fstab1 # decrypt enter des-ede3-cbc decryption password: # enter the password for encryption [[email protected] ~] # Cat fstab1 # view decrypted files #/etc/fstab # Created by Anaconda on Fri Dec 26 18:09:56 2014 # accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab (5), findfs (8), Mount (8) and/or blkid (8) for more info #/dev/mapper/vg_magine3562-lv_root/ext4 defaults 1 1 UUID = d507dc4f-dcaa-4311-9aa6-3392322b064c/boot ext4 defaults 1 2/dev/mapper/vg_magine3562-lv_home/home ext4 defaults 1 2/dev/mapper /vg_magine3562-lv_swap swap defaults 0 0 tmpfs/dev/SHM tmpfs defaults 0 0 devpts/dev/PTS devpts gid = 5, mode = 620 0 0 sysfs/sys sysfs defaults 0 0 proc/proc defaults 0 0

Iii. unidirectional encryption

One-way encryption (also called hash algorithm) if no data fingerprint is generated, it is also called the data digest algorithm, the output is fixed length, the MD5 is 128-Bit fixed-length output, and the sha1 fixed-length output is 160-bit, its feature is not collision every data, as long as there is a difference, will produce a huge change, we call this as an avalanche effect, commonly used algorithms MD5, sha1, sha512, commonly used tools include sha2sum, md5sum, cksum, openSSL DGST.
[[Email protected] ~] # OpenSSL DGST-MD5-hex fstab # extract the signature MD5 (fstab) = 653db83e6cdb396784a60b6ee2f9c2aa [[email protected] ~] # Same as the md5sum fstab # algorithm, the result will also be the same as 653db83e6cdb396784a60b6ee2f9c2aa fstab

OpenSSL encryption and decryption

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.