Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use DES_ncbc_encrypt in C language

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to use DES_ncbc_encrypt in c language". In daily operation, I believe many people have doubts about how to use DES_ncbc_encrypt in c language. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about how to use DES_ncbc_encrypt in c language. Next, please follow the editor to study!

1. First install the SSL library file

Sudo apt-get install libssl-dev

Import header file

# include

two。 Define the calling method

Void call_cbc () {DES_cblock key; / / DES_random_key (& key); / / 64 random bits DES_string_to_key ("pass", & key) generated by random number algorithm; / / string generation key DES_key_schedule schedule; / / literally means password table DES_set_key_checked (& key, & schedule); printf ("cbc mode encryption and decryption:\ n") Unsigned char* input = "My name is XuHuayong"; / / encrypted input string long len = (strlen (input) + 7) / 8encrypted 8ram / length printf ("before encryption:% d\ n", len); unsigned char* output= (char*) malloc (len); DES_cblock ivec; memset ((char*) & ivec, 0, sizeof (ivec)); / / ivec clear 0 printf ("% s\ n", input) DES_ncbc_encrypt (input, output, strlen (input), & schedule, & ivec, DES_ENCRYPT); printf ("after encryption:"); int i; for (I = 0; I < strlen (output); iTunes +) printf ("x", output [I]); / / print binary hexadecimal numbers printf ("\ n") per character; memset ((char*) & ivec, 0, sizeof (ivec)) / input= (char*) malloc (len); / /? DES_ncbc_encrypt (output, input, len, & schedule, & ivec, DES_DECRYPT); printf ("decrypted:% s\ n", input);}

If there is no comment to the above program, there will be a "segment error (core has been dumped)", meaning that the input pointer points to a fixed allocation of space

(not a length problem) the content cannot be changed to cause a segment error, and if the comment section reassigns space to it, a value can be assigned.

For example:

Unsigned char * input1 = "My name is XuHuayong"; / / encrypted input string unsigned char input2 [21] = "My name is XuHuayong"; / / encrypted input string strcpy (input1, "abcd")

There is also a "segment error (core has been dumped)" when strcpy uses assignments, but there is no error if you reallocate space for it or change it to input2.

At this point, the study on "how to use DES_ncbc_encrypt in c language" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report