开发者

How do make my encryption algorithm encrypt more than 128 bits?

OK, now I have coded for an implementation of AES-128 :) It is working fine.

It takes in 128 bits, encrypts and returns 128 bits

So how do i enhance my function so that i开发者_如何学运维t can handle more than 128 bits?

How do i make the encryption algorithm handle larger strings?

Can the same algorithm be used to encrypt files? :)

The function definition is

public byte[] Cipher(byte[] input)
{

}


There are various "chained" or "codebook" modes that you can run a block cipher in. You'll need to read about them and decide which you're going to support. You'll also need to decide what sort of block padding you'll do for partially filled terminal blocks.

Have a read of http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation to start with.

Yes, of course you can encrypt files. You just write the blocks out to another file.

Get a copy of Applied Cryptography if you've not already got one. It's the best intro into this sort of thing that I've read even though it's quite long in the tooth now.


First, don't implement cryptographic algorithms yourself - use an implementation created by experts. Chances are good that you will make errors and build an insecure system. The .NET Framework has extensive build-in support for cryptography in the System.Security namespace including an AES algorithm imlementation. (The former does not apply if you are doing it for the sake of fun ;)

The encode data larger the block size you have to choose an operation mode. Wikipedia lists the most common ones here and some more usually used for disc encryption here.


If this is a learning exercise, great - do what everyone else said.

If this is going anywhere near production systems, confidential data, etc - stop right there. DO NOT WRITE YOUR OWN ENCRYPTION CODE, EVER. There are a million very subtle ways to screw it up and only one way to get it right. I'm sure you're a regular genius and all, but the strong likelihood is that you will unintentionally write subtly broken, easily compromised code without even knowing it; everyone does - that's just how it works.

If this is for a real project, do yourself a massive favour and use some tried and tested encryption libraries which have suffered the slings and arrows of outrageous fortune, survived the trials of life in the wild world, been attacked, patched and are still standing.

Besides, I'm sure you've got enough to do already :)


There is a C++ open source library Crypto++ http://www.cryptopp.com/ Athough it seems that you are trying to implement it in Java, I think maybe it worth while to take a look. After all, it is all about algorithm...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜