Hi guys,
I want to encrypt/decrypt a file
with AES in CTR mode using crypto++ library.
To encrypt a file using AES in CTR mode
the solution is something like this - int CRYPTOPP_API main(int argc, char *argv[])
-
{
-
std::string command, executableName, macFilename;
-
-
if (argc < 2)
-
command = 'h';
-
else
-
command = argv[1];
-
-
if (command == "ae")
-
AES_CTR_Encrypt(argv[2], argv[3], argv[4], argv[5]);
-
}
-
-
void AES_CTR_Encrypt(const char *hexKey, const char *hexIV, const char *infile, const char *outfile)
-
{
-
SecByteBlock key = HexDecodeString(hexKey);
-
SecByteBlock iv = HexDecodeString(hexIV);
-
CTR_Mode<AES>::Encryption aes(key, key.size(), iv);
-
FileSource(infile, true, new StreamTransformationFilter(aes, new FileSink(outfile)));
-
}
This is the solution as per given in crypto++ lib
In the command line if I pass - crypttest "2b7e151628aed2a6abf7158809cf4f3c" "000102030405060708090a0b0c0d0e0f" samp.txt encoded.txt
where - "2b7e151628aed2a6abf7158809cf4f3c" is my key;
-
"000102030405060708090a0b0c0d0e0f" is my initialization vector;
The file is encoded fine.
Now suppose I have a password
const char* password = "somePasswo rd";
Now I want the file to be encoded using this password. How do I do this?
I tried passing "password" as arg[2] in AES_CTR_Encrypt function, I get error telling - "CryptoPP::Exception caught: AES/CTR: 1 is not a valid key length"
Also I have problem using argv[3] in AES_CTR_Encrypt function which is initialization
vector. How do I calculate different IV values for different files???
Problem decrypting the same file
To decrypt the file with the same password, I tried defining - void AES_CTR_Decrypt(const char *hexKey, const char *hexIV, const char *infile, const char *outfile)
-
{
-
SecByteBlock key = HexDecodeString(hexKey);
-
SecByteBlock iv = HexDecodeString(hexIV);
-
CTR_Mode<AES>::Decryption aes(key, key.size(), iv);
-
FileSource(infile, true, new StreamTransformationFilter(aes, new FileSink(outfile)));
-
}
but I dont get back the original file.
What is that I need to decrypt a file????
How can I encrypt/decrypt a file with AES in CTR mode when I have a password????
You can refer to this link to get access to crypto++ lib
http://www.cryptopp.co m/
Eagerly waiting for a reply.
5 3760 DeMan 1,806
Top Contributor
Hiya,
What is in your samp.text file? It appears to me that you may inadvertently be passing in the wrong parameters -> specifically that
AES_CTR_Encrypt (argv[2], argv[3], argv[4], argv[5]);
should be
AES_CTR_Encrypt (argv[1], argv[2], argv[3], argv[4]);
.Alternatively, I think the call may be correct, but you may have missed an input parameter -> it appears you expect the encryption type to be specified (as "ae"), but you never give that on the command line (which is a little odd since you definitely seem to be calling something in the Crypto Library (judging by the error).
Hiya,
What is in your samp.text file? It appears to me that you may inadvertently be passing in the wrong parameters -> specifically that
AES_CTR_Encrypt (argv[2], argv[3], argv[4], argv[5]);
should be
AES_CTR_Encrypt (argv[1], argv[2], argv[3], argv[4]);
.Alternatively, I think the call may be correct, but you may have missed an input parameter -> it appears you expect the encryption type to be specified (as "ae"), but you never give that on the command line (which is a little odd since you definitely seem to be calling something in the Crypto Library (judging by the error).
Thanks for your reply.
My input file "samp.text" contains - # connection table version 2
-
35 0 0 3 0 0 0 0 0 1.2063 0.4 0 1
-
17 0 0 4 0 0 0 0 0 0 0.41875 0 1
-
6 2 1 1 4 4 0 0 0 0.9625 0.0125 0 1
-
6 2 1 2 3 3 0 0 0 0.4 0 0 1
-
CIS 1 2
I have passed
crypttest ae key vi samp.text Encoded.text in the command line
where
crypttest-->program name -->argv[0]
ae-->to ensure that aes algorithm is executed -->argv[1]
key-->key passed as shown in above thread -->argv[2]
vi--> Initialization Vector -->argv[3]
samp.text-->Input fileName -->argv[4]
Encoded.text-->Output FileName -->argv[5]
I have no problems passing input parameters. I need to know when I have a password how do I calculate key and IV based on password?????
I have a password say "somepasswo rd"
Now using this "somepasswo rd" how can I calculate key and IV ????
Please see the code provided by crypto++ library..You will get a clear idea about what I want.. See usage.txt file to see " Encryption on AES in CTR mode "
I also want to know how I can decrypt the file, as crypto++ lib provides function only for encryption.
please help guys...
This is really important to me.....
DeMan 1,806
Top Contributor
Have you tried padding the password (with some sort of data) to be the same length as the key you passed earlier. It's interesting that the key length there is 32 bytes (which being a power of 2 makes me think it has to be that size)
Try padding it out to the right length. I'm not familiar enough with AES to be able to say whether padding it out with 0x0 or 0xff is enough, or whether this makes for a WEAK cipher.
You could try to create a string that is 32 bytes long and use the first (or last)
32 - n (where n is your password length) characters to pad it out.
RedSon 5,000
Recognized Expert Expert
You probably need to hash your password first to make it the correct length. Then use this hash as the key, then when you again enter your password to decrypt has the password again and then decrypt with that hash.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Stu |
last post by:
Hi,
Im reading a file in from disk as a byte array then passing it to a memory
stream for decryption using crypto api functions. What I have found is that
you need to
reduce the array length by 2 from the original lenght in order to get it to
work
as there seems to be 2 extra 0 bytes at the end.
Functions included
Stu
|
by: Bryan Olson |
last post by:
The current Python standard library provides two cryptographic
hash functions: MD5 and SHA-1 . The authors of MD5 originally
stated:
It is conjectured that it is computationally infeasible to
produce two messages having the same message digest.
That conjecture is false, as demonstrated by Wang, Feng, Lai and
Yu in 2004 . Just recently, Wang, Yu, and Lin showed a short-
cut solution for finding collisions in SHA-1 . Their result
|
by: Michael Sparks |
last post by:
Hi,
I suspect this is a bug with AMK's Crypto package from
http://www.amk.ca/python/code/crypto , but want to
check to see if I'm being dumb before posting a bug
report.
I'm looking at using this library and to familiarise myself writing
small tests with each of the ciphers. When I hit Crypto.Cipher.ARC4 I've
|
by: Andy Chau |
last post by:
I try to use RSA to implement the following scheme but wasn't sucessful.
Sever encrypt a message using a public key, the client decrpyt the message
using a private key.
I don't want the client to be able to encrypt a message.
However, using the Crypto API I need to pass in both the private and public
key pairs in order to decrypt the message.
When the client has both private and public key, it can just use the public
|
by: Slug |
last post by:
Hello all,
I've been trying to get a public key solution working but have been having a
few problems. For starters there is a lot of contradictory information out
there, MSDN is not much help, and a lot of the sample code available I have
found are buggy so don't provide much insight.
Unfortunately for me every developer I know either gives me a completely
blank look when I try to talk crypto, or they have some wildly inaccurate
and...
| |
by: mirandacascade |
last post by:
I am attempting to implement a process, and I'm pretty sure that a
major roadblock is that I do not understand the nomenclature. The
specs indicate that the goal is to calculate a message digest using an
SHA-256 algorithm. There are 2 examples included with the specs. The
label on the 2 examples are: 'HMAC samples'. In both examples, the
message on which the digest is to be calculated is (the 33 chars within
the quotes):
'This is a...
|
by: GiBo |
last post by:
Hi
I need some encryption done in my Python 2.5 application. I wonder
what's the most recommended library? I've found M2crypto and some
OpenSSL wrappers and Python Cryptography Toolkit and some others. No
surprise I'm confused :-)
What's the most often used library for crypto?
For now I need a simple AES, no asymmetric crypto or GPG involved.
|
by: vermarajeev |
last post by:
Hi guys,
I have written code to encrypt and decrypt files using perl script. Please help me to port below code to crypto++ library.
//ENCRYPTION
my $cipher = Crypt::CBC->new(
-cipher => "Crypt::Rijndael",
-key => $key,
-header => 'salt',
);
|
by: Fett |
last post by:
I need a crypto package that works on windows with python 2.5. Can
anyone suggest one for me?
I have been searching for a couple days for a good cryptography
package to use for public/private key encryption, at this point I
would settle for symmetric even.
Every encryption package I have found for python was either operating
system specific (read *nix only):
http://www.freenet.org.nz/ezPyCrypto/
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
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...
|
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
| |
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...
| |