Comments (4)
with Util.Encoders.AES;
with Util.Streams;
with Util.Streams.Files;
with Util.Streams.AES;
with Util.Encoders;
with Ada.Command_Line;
with Text_IO; use Text_IO;
with Ada.Characters.Handling;
with Ada.Streams.Stream_IO;
with Util.Streams.Texts;
procedure Ada_Aes is
use Ada.Command_Line;
function Base32_Encode (S : String) return String is
use Util.Encoders;
C : constant Encoder := Util.Encoders.Create ("base32");
begin
return C.Encode ((S));
end Base32_Encode;
function Base32_Decode (S : String) return String is
use Ada.Characters.Handling;
use Util.Encoders;
D : constant Decoder := Util.Encoders.Create ("base32");
begin
return D.Decode (To_Upper (S));
end Base32_Decode;
procedure Decrypt_File (Source : String; Destination : String; Key : String)
is
In_Stream : aliased Util.Streams.Files.File_Stream;
Out_Stream : aliased Util.Streams.Files.File_Stream;
Decipher : aliased Util.Streams.AES.Decoding_Stream;
Password_Key :
constant Util.Encoders.Secret_Key
(Length => Util.Encoders.AES.AES_128_Length) :=
Util.Encoders.Create (Base32_Decode (Key));
begin
In_Stream.Open (Ada.Streams.Stream_IO.In_File, Source);
Out_Stream.Create
(Mode => Ada.Streams.Stream_IO.Out_File, Name => Destination);
Decipher.Produces
(Output => Out_Stream'Unchecked_Access, Size => 65_536);
Decipher.Set_Key (Secret => Password_Key, Mode => Util.Encoders.AES.CTR);
Util.Streams.Copy (From => In_Stream, Into => Decipher);
end Decrypt_File;
procedure Encrypt_File (Source : String; Destination : String; Key : String)
is
In_Stream : aliased Util.Streams.Files.File_Stream;
Out_Stream : aliased Util.Streams.Files.File_Stream;
Cipher : aliased Util.Streams.AES.Encoding_Stream;
Password_Key :
constant Util.Encoders.Secret_Key
(Length => Util.Encoders.AES.AES_128_Length) :=
Util.Encoders.Create (Base32_Decode (Key));
begin
In_Stream.Open (Ada.Streams.Stream_IO.In_File, Source);
Out_Stream.Create
(Mode => Ada.Streams.Stream_IO.Out_File, Name => Destination);
Cipher.Produces (Output => Out_Stream'Unchecked_Access, Size => 65_536);
Cipher.Set_Key (Secret => Password_Key, Mode => Util.Encoders.AES.CTR);
Util.Streams.Copy (From => In_Stream, Into => Cipher);
end Encrypt_File;
begin
if Argument_Count /= 4 then
Put_Line ("Correct usage:");
Put_Line
(Ada.Command_Line.Command_Name &
" encode input.dat output.dat <base32encodedkey>");
Put_Line
(Ada.Command_Line.Command_Name &
" decode input.dat output.dat <base32encodedkey>");
return;
end if;
declare
Cipher_Mode : String := Argument (1);
Input_File : String := Argument (2);
Output_File : String := Argument (3);
Key : String := Argument (4);
begin
if Cipher_Mode = "encode" then
Encrypt_File
(Source => Input_File, Destination => Output_File, Key => Key);
return;
end if;
if Cipher_Mode = "decode" then
Decrypt_File
(Source => Input_File, Destination => Output_File, Key => Key);
return;
end if;
Put_Line ("Unrecognized function");
return;
end;
end Ada_Aes;
from ada-util.
Thanks to have found that issue!
from ada-util.
CFB encryption has the same issue.
from ada-util.
The unit tests are wrong and don't test correctly the CFB, OFB and CTR modes.
The tests in regtests/util-streams-tests.adb instantiate a generic procedure with the encryption mode but for the CFB, OFB and CTR tests, they are instantiated with AEC.PCBC mode!!!!!
Fixing these tests, raises the issue!
from ada-util.
Related Issues (20)
- Typo in procedure name HOT 2
- aws-client-ext__2.adb fails to compile HOT 14
- No HTTP manager is defined (even though one should be) HOT 5
- link of util_harness.adb failed
- Custom log appender HOT 5
- utilada_aws: raised PROGRAM_ERROR : SSL not supported. HOT 2
- Logger: add a way to filter logs HOT 1
- utilada_curl crate uses wrong curl dependency
- Add HOTP algorithm
- Support to build with -gnatW8
- Allow to read stdout and stderr as separate streams when spawning a process
- Input stream reader to read parts from another stream
- Support to ignore line breaks when decoding Base64 streams
- Improvement of test framework to launch and verify external program execution and output
- Alire lost reference to `utils-streams-buffered-parts.ads` HOT 3
- util-files.adb "Into : out unbounded_string" not initialized HOT 1
- Change the log time from UTC to Local Time HOT 2
- Perf report generates incorrect XML title attributes
- Executor does not always stop the worker tasks
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ada-util.