473,651 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I encrypt string using the MD5 method?

Is there a function to do this ?
with the string parameter,it return the encryption result of the string
?

Nov 15 '05 #1
14 4642
In article <11************ *********@f14g2 000cwb.googlegr oups.com>,
sh*****@gmail.c om <sh*****@gmail. com> wrote:
Is there a function to do this ?
with the string parameter,it return the encryption result of the string


MD5 is not an encryption function: it is a hash function.

There are no encryption functions specified by the C standards.
No hash functions either.

There are a number of fairly portable MD5 libraries. See for example
http://sourceforge.net/projects/libmd5-rfc/

I had a look at the above code, and it looks to be fairly
standard C -- except that at one point it attempts to determine
whether the machine is "big endian" or "little endian" and it
appears to me at first look that the test done for that might perhaps
not be completely portable, perhaps failing on machines whose
short is the same size as int.

--
Ceci, ce n'est pas une idée.
Nov 15 '05 #2
Thank you for reply!
In PHP there is a md5() function to do this and I think if there is an
equal function in C.
By the way,is there any better encryption method than MD5??

Nov 15 '05 #3
sh*****@gmail.c om said:
Thank you for reply!
In PHP there is a md5() function to do this and I think if there is an
equal function in C.
By the way,is there any better encryption method than MD5??


MD5 is not an encryption method. It's a hashing method.

Whether one encryption method is "better" than another depends on what you
mean by "better". Faster? Easier key distro? More secure? ROT-26 is way
faster than AES. It's much easier to solve the key distribution problem for
AES than for OTP. OTP is vastly (infinitely?) more secure than ROT-26.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/2005
http://www.cpax.org.uk
email: rjh at that domain (but drop the www, obviously)
Nov 15 '05 #4
My better means more secure.
So as you say OTP may be the answer.
How can use it in C?Could you give me some advice?

Nov 15 '05 #5
sh*****@gmail.c om said:
My better means more secure.
So as you say OTP may be the answer.
Unlikely, even though it is information-theoretically secure (which means
that, used properly, it is provably uncrackable).
How can use it in C?
void otp(unsigned char *o,
const unsigned char *i,
const unsigned char *k,
size_t len)
{
while(len--)
{
*o++ = *i++ ^ *k++;
}
}
Could you give me some advice?


In OTP, the key has to be as long as the message, completely random, and
never re-used. This leads to practical problems in key distribution which
render the OTP useless for many purposes. Having said that, for 100%
security it can't be beaten, which is why you used to see so many film
snippets in the 1970s where politicians visiting other countries would
always have a courier with them with a briefcase chained to his wrist. Ever
wonder what was in the briefcase? Key material!

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/2005
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Nov 15 '05 #6
You say the following is its main implementation:
void otp(unsigned char *o,
const unsigned char *i,
const unsigned char *k,
size_t len)
{
while(len--)
{
*o++ = *i++ ^ *k++;
}
}

?

Nov 15 '05 #7
sh*****@gmail.c om said:
You say the following is its main implementation:
void otp(unsigned char *o,
const unsigned char *i,
const unsigned char *k,
size_t len)
{
while(len--)
{
*o++ = *i++ ^ *k++;
}
}

?


Yes. The OTP is a remarkably simple algorithm, and guaranteed uncrackable if
used correctly.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/2005
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Nov 15 '05 #8
In article <11************ *********@g49g2 000cwa.googlegr oups.com>,
sh*****@gmail.c om <sh*****@gmail. com> wrote:
You say the following is its main implementation:
Please note, other people are not reading by threading newsreaders, or might
not have received the previous message yet, or the message might have
expired for them. [I've seen expiration times set as low as 4 hours
on some newsservers.] It is therefore best to include enough context
for people to know what you are talking about.

In this particular case, "its" does not have meaning without the
discussion context. The missing referant is that you are discussing
implementation of OTP (One Time Pads).

[You also left out the attribution, so we can't easily tell who
wrote the code you quoted.]
void otp(unsigned char *o,
const unsigned char *i,
const unsigned char *k,
size_t len)
{
while(len--)
{
*o++ = *i++ ^ *k++;
}
} ?

Yes, that is a complete and correct implementation of One Time Pad
encryption.

i is the input stream of bytes. i is -not- constrained to be a "string":
NUL bytes are acceptable input. Because of that, the length of the
input is passed in len.

k is the keying material. The key must be as long as the input. As the
previous poster remarked, you must not reuse the key material, or else
the security of your OTP is severely put at risk. The key must *not* be
from a "random number generator": it must be truly random, such as
from physically flipping coins millions of times, or from
radioactive decay. This randomness is important!!! Note: random NUL bytes
are acceptable in the key material, so k is not a "string" either.

o is the output buffer, which must be as long as the input. It is
possible for the encryption process to result in NUL bytes in places,
so s is not a "string" either.

The output really is just formed from the input xor'd with the key.
When the output is xor'd with the key, the result would be the
input back again. But first you have to get a copy of the key to
the recipient; that's what the other poster was referring to as
"key distribution".
--
Any sufficiently old bug becomes a feature.
Nov 15 '05 #9
In article <11************ **********@f14g 2000cwb.googleg roups.com>,
sh*****@gmail.c om <sh*****@gmail. com> wrote:
In PHP there is a md5() function to do this and I think if there is an
equal function in C.


Not in the C standard, but you can find md5 code in several places
such as the one I referced.

PHP has gone through a number of versions; earlier versions did
not have md5(). C goes through very very few official versions.

PHP is expected to provide -all- of the functions defined for
its current version, and the functions that will be called upon
are not known until runtime, so PHP can end up being a largish
executable. C expects that you will link in only the functions
you need for a particular task, so C can end up with small fast
executables.
--
"Who Leads?" / "The men who must... driven men, compelled men."
"Freak men."
"You're all freaks, sir. But you always have been freaks.
Life is a freak. That's its hope and glory." -- Alfred Bester, TSMD
Nov 15 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
7948
by: wqhdebian | last post by:
As far as I know,when encrypt or decrypt ,a key must first be got,and the key is first generate by a tool or from SecurityRandom,that means I can not generate the same key with the same input.Does there is a method which can generate a same with the same input string? There is a need to transfer file between to site,and the customer wish to encrypt these files during transfering,and they want to store a string into each database at...
4
28283
by: Spikinsson | last post by:
I'm looking for a good decrypt/encrypt function, all I want is a function in this form: char* encrypt(char* normal) { ... return encrypted; } and
10
9597
by: Javier Gomez | last post by:
I have a table with 15.000 records. How can encrypt all information if after will shown in a form (text box)decryted ????? Thanks in advance Javier Gomez
14
7682
by: msnews.microsoft.com | last post by:
How can I encrypt and decrypt string?
20
4161
by: Drebin | last post by:
It's a long story really, but the bottom line is we need to encrypt or obfuscate a clear-text 9-digit SSN/taxpayer ID into something less than 21 characters. It doesn't need to be super-secure, just something that isn't plain-text and it HAS to be as unique as the original number. It also does not need to be a symmetric algorithm - we are using this as a way to create a unique "userid" on a system to which we single-signon. So it's used...
7
26773
by: Matthias S. | last post by:
Hi, I had a look at the vast information on encryption in the MSDN and got pretty confused. All I want to do is to encrypt a string into an encrypted string and later decrypt that (encrypted) string again to a human readable form. Can't be that difficult :). Could you send me please into the right direction. Thanks in advance. --
4
9075
by: Hrvoje Voda | last post by:
Does anyone knows a good example of how to encrypt/decrypt a string? Hrcko
4
4704
by: google | last post by:
OK, I know how to encrypt and decrypt data, but here's the deal: I have a large Winforms .NET 2.0 application which is currently storing the connection string in the app.config file unencrypted (currently using Windows integrated security, so there's no password). There are only 3 users using the app right now, but that will change soon and we're not going to have our DBAs add every user to the database... Our data entry personnel have...
4
6358
by: tomtown.net | last post by:
Hello I'm using the File.Encrypt method (.net 2.0) to encrypt files and folders (mark for encryption) on a local disk (XP SP2, 3DES, .net 2.0). Unfortunatelly I get an exception when trying to mark the %desktop% folder for encryption: "The process cannot access the file because it is being used by another process). Is there any possibility I can close handles that use the folder? Thanks a lot in advance
3
8270
by: JDeats | last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting and decrypting a file. http://support.microsoft.com/kb/307010 In .NET 2.0 this approach is not fully supported (a .NET 2.0 build with these methods, will appear to encrypt and decrypt, but the resulting decrypted file will be corrupted. I tried encrypting a .bmp file and then decrypting, the resulting decrypted file under .NET 2.0 is garbage, the .NET 1.1 build works...
0
8357
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8700
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8465
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8581
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7298
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5612
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2701
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1588
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.