logo
down
shadow

How to generate Key and Key IV aes in C#


How to generate Key and Key IV aes in C#

By : Advait Vasavada
Date : September 29 2020, 06:00 AM
may help you . Let's do it step by step to keep things simple.
You need two methods to achieve your goal. I'll start with encryption method:
code :
static byte[] Encrypt(string input, byte[] Key, byte[] IV)
{
    byte[] encryptedBytes;

    using (RijndaelManaged rijndael = new RijndaelManaged())
    {
        rijndael.Key = Key;
        rijndael.IV = IV;

        ICryptoTransform encryptor = rijndael.CreateEncryptor(rijndael.Key, rijndael.IV);

        using (var memoryStream = new MemoryStream())
        {
            using (var cryptoStream = new CryptoStream(memoryStream,
                    encryptor, CryptoStreamMode.Write))
            {
                using (var streamWriter = new StreamWriter(cryptoStream))
                {
                    streamWriter.Write(input);
                }
                encryptedBytes = memoryStream.ToArray();
            }
        }
    }
    return encryptedBytes;
}
static string Decrypt(byte[] cipher, byte[] Key, byte[] IV)
{
    string plaintext = null;

    using (RijndaelManaged rijndael = new RijndaelManaged())
    {
        rijndael.Key = Key;
        rijndael.IV = IV;

        ICryptoTransform decryptor = rijndael.CreateDecryptor(rijndael.Key, rijndael.IV);

        using (var memoryStream = new MemoryStream(cipher))
        {
            using (var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read))
            {
                using (var streamReader = new StreamReader(cryptoStream))
                {
                    plaintext = streamReader.ReadToEnd();
                }
            }
        }

    }

    return plaintext;
}
string original = "This is what would be encrypted!";

using (RijndaelManaged myRijndael = new RijndaelManaged())
{

    myRijndael.GenerateKey(); // this line generates key
    myRijndael.GenerateIV(); // this line generates initialization vektor

    // This line returns encrypted text
    byte[] encryptedBytes = Encrypt(original, myRijndael.Key, myRijndael.IV);

    // You can decrypt the encrypted text like so
    string decryptedString = Decrypt(encryptedBytes, myRijndael.Key, myRijndael.IV);
}


Share : facebook icon twitter icon
Why does Visual Studio 2010 compiler for VB.Net still generate pdb files in my bin folder when I have "Generate deb

Why does Visual Studio 2010 compiler for VB.Net still generate pdb files in my bin folder when I have "Generate deb


By : Ramsha Abid
Date : March 29 2020, 07:55 AM
may help you . Are you certain that you have changed it for the correct build config. eg. You changed it for Release but you are compiling under debug?
generate inside generate verilog + error near generate(veri - 1137)

generate inside generate verilog + error near generate(veri - 1137)


By : asubhani
Date : March 29 2020, 07:55 AM
this will help You are a long long way from where you should be.
Verilog is not a programming language; it is a hardware description language. You model hardware as a network of concurrent processes. Each process models a small bit of hardware such as a counter, a state machine, a shift-register, some combinational logic... In Verilog, each process is coded as an always block. So, one always statement never ever can appear inside another; that makes no sense.
code :
module N_FLOPS #(n = 2, DATA_WIDTH = 8) (input [DATA_WIDTH:0] dina, input clk, en, output [DATA_WIDTH:0] douta);

  reg [DATA_WIDTH:0] flops [n-1:0];

  always @(posedge clk)
    if (en)
      begin : SR
        integer i;
        flops[0] <= dina;
        for (i = 1; i <= n ; i = i + 1) 
          flops[i] <= flops[i-1];
      end

  assign douta = flops[n-1];

endmodule
always @(posedge CLOCK)  // or negedge
  begin
    // do things that occur on the rising (or falling) edge of CLOCK
    // stuff here gets synthesised to combinational logic on the D input
    // of the resulting flip-flops
  end
maven-antrun-plugin: generate sources for protobuf does not generate Java files

maven-antrun-plugin: generate sources for protobuf does not generate Java files


By : tikandak
Date : March 29 2020, 07:55 AM
will be helpful for those in need When in doubt about files not getting created, make sure you use absolute path. In this case, ${basedir} allows us to get the absolute path to the location of the Maven base directory (location of POM):
code :
<mkdir dir="${basedir}/src-gen" />
<exec executable="protoc">
    <arg value="--java_out=${basedir}/src-gen" />
    <arg value="--proto_path=${basedir}" /> <!-- proto_path needs to point to where the proto files are -->
    <arg value="proto/ros/RosTime.proto" />
    <!-- rest of proto files... -->
</exec>
Angular 2: Generate the route link using functions/ Dynamically generate the routerLink

Angular 2: Generate the route link using functions/ Dynamically generate the routerLink


By : Ray
Date : March 29 2020, 07:55 AM
Unable to generate thumbnail generate thumbnails from phpThumb in controller in CakePHP

Unable to generate thumbnail generate thumbnails from phpThumb in controller in CakePHP


By : iknock
Date : March 29 2020, 07:55 AM
I wish this helpful for you I am using CakePHP framework version 2.6.1. , I got the solution guys,
I was doing a single mistake
code :
$propertyImageThumb = $phpThumb->url( $propertyImages['Photo']['image_url'], array(
                'w'  => 1349,
                'h'  => 500,
                'zc' => 1
            ) );
Related Posts Related Posts :
  • Can not convert 'string' to 'int'
  • Passing Type to Method for Use in Generic
  • Getting the value of an integer array from LIST<>
  • Parsing Html tags using c#
  • ListBox Showing First Item Only
  • developing a GUI in C# on Cosmos OS
  • How can I refactor this to work without breaking the pattern horribly?
  • Type Parameter Unification
  • Unit testing an MVC action method with a Cache dependency?
  • Finding a sequence in a List
  • How to read binary column in database into image on asp.net page?
  • Form.Show() is not showing it's child controls
  • Clearing WebBrowser control's cookies for all sites WITHOUT clearing for IE itself
  • Linq 2 Sql DateTime format to string yyyy-MM-dd
  • is there a better way to write this frankenstein LINQ query that searches for values in a child table and orders them by
  • Combine NotifyIcon and ToolTip
  • How to apply custom BidirectionalGraph from QuickGraph to GraphLayout from Graph#?
  • How do I output coloured text from by unit tests in the R# Unit Test Session window in Visual Studio?
  • C# - Getting a RawFraction Performance Counter to show a persistent value
  • Copy a ListView’s Items to the Clipboard in WPF C#
  • How to get the project path at Design Time
  • How do I parse the free format address to save into the DataBase
  • Populate StackPanel with checkbox's from Database
  • .Net/C# Build Tool - Is NAnt a preferred tool?
  • ASP.NET MVC: Localization issues (wrong resx file for culture)
  • WPF Toolkit Pie Chart Style Colors
  • .NET File locking problem
  • How to insert more than 256 columns in a Open Office Calc sheet using c#?
  • Why does FileDialog sometimes not remember the initial directory?
  • ActiveDirectory DirectorySearcher: Check if user is member of a group
  • How can I use Moq here?
  • How to copy file to the C:\Program Files (x86)\
  • Is -10 between 1.5 × 10^-45 and 3.4 × 10^38?
  • Is it possible to get the item index using Contains?
  • save System.Net.mail.MailMessage as .msg file
  • SystemParametersInfo parameter definitions for C#
  • How to add/edit functionality in the same page without flickering?
  • NHibernate generate mappings from classes?
  • How to prevent out-of-range datetime value error?
  • how to inject logger instance to every class that has a property of type ILogger using MEF
  • UDPClient First Time Using -- What's Wrong?
  • Help with debugging COM errors? (.mdi to .pdf file conversions using Microsoft Office Document Imaging)
  • Need to iterate through SQL table rows, one at a time (table too big to use adapter.Fill)
  • Why are virtual methods considered early bound?
  • programatically get public key token using .snk file c#
  • Howto place data from DataSet to List
  • C# what is the size of unmanaged object?
  • C# why sizeof is unsafe and how to get size of a struct in a safe way?
  • NullReferenceException with Ckeditor 5 and ASP.NET MVC bundle error?
  • How to refresh unc path cache?
  • dllexport Struct pointers and returning uint8_t
  • Is it a good practice to have setter in the get instance property of a singleton class
  • How to sort the coordinates of a hash set in C#
  • Multiply 64-bit integers using .NET Core's hardware intrinsics
  • How to parse string data to string and long?
  • Submit Button is not working In Razor asp.net mvc
  • While loop multiple condition check with single variable
  • Inside a catch clause, how can I see an exception without a name
  • How I can use Certificate.pfx for windows exe build
  • I'm trying to detect that SQL Server Compact Edition is installed in a system or not
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk