[cryptopp-users] Re: How to decrypt a file in memory?

2022-09-22 Thread Jeffrey Walton


On Wednesday, September 21, 2022 at 1:59:54 PM UTC-4 kakaa...@gmail.com 
wrote:

> I'm encrypting a file this way:
>
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> 
> 
> void FileEncrypt(byte key[], byte iv[]
>, const std::string& file, const std::string& dest)
> {
> CTR_Mode< AES >::Encryption cipher;
> cipher.SetKeyWithIV(key, strlen((char*)key), iv, 
> strlen((char*)iv));
> 
> std::ifstream in{file, std::ios::binary};
> std::ofstream out{dest, std::ios::binary};
> 
> CryptoPP::FileSource{in, true,
> new CryptoPP::StreamTransformationFilter{
> cipher, new CryptoPP::FileSink{out}}};
> } 
> 
> INT main(INT argc, PCHAR* argv)
> {
> std::string file = "...";
> std::string dest = "...";
> 
> unsigned char* key[] = "p3s6v9y$B)H@Mc";
> unsigned char* iv[] = "VkXp2s5v8y/B?E(H";
> 
> FileEncrypt(key, iv, file, dest);
> FileDecrypt(key, iv, file, dest);
> }
>
>
> Then when needed i'm downloading the encrypted file from my repo.
>
> I've been able to decrypt it with:
>
> ```c++
> void FileDecrypt(byte key[], byte iv[]
>, const std::string& file, const std::string& dest)
> {
>  CTR_Mode< AES >::Decryption cipher;
>  cipher.SetKeyWithIV(key, strlen((char*)key), iv, 
> strlen((char*)iv));
>  
>  std::ifstream in{file, std::ios::binary};
>  std::ofstream out{dest, std::ios::binary};
> 
>  CryptoPP::FileSource{in, true,
>   new CryptoPP::StreamTransformationFilter{
>   cipher, new CryptoPP::FileSink{out}}};
> }
> ```
> But this way the decrypted file is saved to disk, how could i decrypt it 
> on memory without saving to disk?
>

https://www.cryptopp.com/wiki/Sink .

Jeff

-- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cryptopp-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/cryptopp-users/fc563747-2b3c-44bf-b9a2-67dab331b2bdn%40googlegroups.com.


Re: [cryptopp-users] Re: How to decrypt a file in memory?

2022-09-22 Thread Manish sharma
Hi,

How to Launch Smart Contract-Based Cryptocurrency MLM Software?


On Thu, Sep 22, 2022 at 2:31 PM Anton Schmidt 
wrote:

> Just load file data into memory buffer (std::vector) and
> use filter pipeline with VectorSource and VectorSink.
> https://cryptopp.com/docs/ref/class_vector_source.html
> https://cryptopp.com/docs/ref/class_vector_sink.html
>
> четверг, 22 сентября 2022 г. в 00:59:54 UTC+7, kakaa...@gmail.com:
>
>> I'm encrypting a file this way:
>>
>>
>> #include 
>> #include 
>> #include 
>> #include 
>> #include 
>> #include 
>> #include 
>> #include 
>>
>>
>> void FileEncrypt(byte key[], byte iv[]
>>, const std::string& file, const std::string& dest)
>> {
>> CTR_Mode< AES >::Encryption cipher;
>> cipher.SetKeyWithIV(key, strlen((char*)key), iv,
>> strlen((char*)iv));
>>
>> std::ifstream in{file, std::ios::binary};
>> std::ofstream out{dest, std::ios::binary};
>>
>> CryptoPP::FileSource{in, true,
>> new CryptoPP::StreamTransformationFilter{
>> cipher, new CryptoPP::FileSink{out}}};
>> }
>>
>> INT main(INT argc, PCHAR* argv)
>> {
>> std::string file = "...";
>> std::string dest = "...";
>>
>> unsigned char* key[] = "p3s6v9y$B)H@Mc";
>> unsigned char* iv[] = "VkXp2s5v8y/B?E(H";
>>
>> FileEncrypt(key, iv, file, dest);
>> FileDecrypt(key, iv, file, dest);
>> }
>>
>>
>> Then when needed i'm downloading the encrypted file from my repo.
>>
>> I've been able to decrypt it with:
>>
>> ```c++
>> void FileDecrypt(byte key[], byte iv[]
>>, const std::string& file, const std::string& dest)
>> {
>>  CTR_Mode< AES >::Decryption cipher;
>>  cipher.SetKeyWithIV(key, strlen((char*)key), iv,
>> strlen((char*)iv));
>>
>>  std::ifstream in{file, std::ios::binary};
>>  std::ofstream out{dest, std::ios::binary};
>>
>>  CryptoPP::FileSource{in, true,
>>   new CryptoPP::StreamTransformationFilter{
>>   cipher, new CryptoPP::FileSink{out}}};
>> }
>> ```
>> But this way the decrypted file is saved to disk, how could i decrypt it
>> on memory without saving to disk?
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Crypto++ Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cryptopp-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/cryptopp-users/15333873-9cf5-428e-a22b-82b9f9b5b5e8n%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cryptopp-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/cryptopp-users/CABUB1NT5UToHVdoQoUDWPjaRxth2K4YXMyLAmBuyw88kJ_F7Gw%40mail.gmail.com.


[cryptopp-users] Re: How to decrypt a file in memory?

2022-09-22 Thread Anton Schmidt
Just load file data into memory buffer (std::vector) and 
use filter pipeline with VectorSource and VectorSink.
https://cryptopp.com/docs/ref/class_vector_source.html
https://cryptopp.com/docs/ref/class_vector_sink.html

четверг, 22 сентября 2022 г. в 00:59:54 UTC+7, kakaa...@gmail.com: 

> I'm encrypting a file this way:
>
>
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> 
> 
> void FileEncrypt(byte key[], byte iv[]
>, const std::string& file, const std::string& dest)
> {
> CTR_Mode< AES >::Encryption cipher;
> cipher.SetKeyWithIV(key, strlen((char*)key), iv, 
> strlen((char*)iv));
> 
> std::ifstream in{file, std::ios::binary};
> std::ofstream out{dest, std::ios::binary};
> 
> CryptoPP::FileSource{in, true,
> new CryptoPP::StreamTransformationFilter{
> cipher, new CryptoPP::FileSink{out}}};
> } 
> 
> INT main(INT argc, PCHAR* argv)
> {
> std::string file = "...";
> std::string dest = "...";
> 
> unsigned char* key[] = "p3s6v9y$B)H@Mc";
> unsigned char* iv[] = "VkXp2s5v8y/B?E(H";
> 
> FileEncrypt(key, iv, file, dest);
> FileDecrypt(key, iv, file, dest);
> }
>
>
> Then when needed i'm downloading the encrypted file from my repo.
>
> I've been able to decrypt it with:
>
> ```c++
> void FileDecrypt(byte key[], byte iv[]
>, const std::string& file, const std::string& dest)
> {
>  CTR_Mode< AES >::Decryption cipher;
>  cipher.SetKeyWithIV(key, strlen((char*)key), iv, 
> strlen((char*)iv));
>  
>  std::ifstream in{file, std::ios::binary};
>  std::ofstream out{dest, std::ios::binary};
> 
>  CryptoPP::FileSource{in, true,
>   new CryptoPP::StreamTransformationFilter{
>   cipher, new CryptoPP::FileSink{out}}};
> }
> ```
> But this way the decrypted file is saved to disk, how could i decrypt it 
> on memory without saving to disk?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cryptopp-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/cryptopp-users/15333873-9cf5-428e-a22b-82b9f9b5b5e8n%40googlegroups.com.