logo
down
shadow

AES encryption in JS equivalent of C#


AES encryption in JS equivalent of C#

Content Index :

AES encryption in JS equivalent of C#
Tag : javascript , By : baumichel
Date : November 28 2020, 04:01 AM

this will help Here is the example how to reproduce the same ciphertext between C# and CryptoJS:
static void Main(string[] args)
{
    byte[] plainText = Encoding.Unicode.GetBytes("Example String"); // this is UTF-16 LE
    string cipherText;
    using (Aes encryptor = Aes.Create())
    {
        var pdb = new Rfc2898DeriveBytes("Example Key", Encoding.ASCII.GetBytes("Ivan Medvedev"));
        encryptor.Key = pdb.GetBytes(32);
        encryptor.IV = pdb.GetBytes(16);
        using (MemoryStream ms = new MemoryStream())
        {
            using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write))
            {
                cs.Write(plainText, 0, plainText.Length);
                cs.Close();
            }
            cipherText = Convert.ToBase64String(ms.ToArray());
        }
    }

    Console.WriteLine(cipherText);
}
var keyBytes = CryptoJS.PBKDF2('Example Key', 'Ivan Medvedev', { keySize: 48 / 4, iterations: 1000 });
// take first 32 bytes as key (like in C# code)
var key = new CryptoJS.lib.WordArray.init(keyBytes.words, 32);
// skip first 32 bytes and take next 16 bytes as IV
var iv = new CryptoJS.lib.WordArray.init(keyBytes.words.splice(32 / 4), 16);
// use the same encoding as in C# code, to convert string into bytes
var data = CryptoJS.enc.Utf16LE.parse("Example String");
var encrypted = CryptoJS.AES.encrypt(data, key, { iv: iv });
console.log(encrypted.toString());

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

ASP equivalent encryption in PHP?


Tag : php , By : Adrian Codrington
Date : March 29 2020, 07:55 AM
To fix the issue you can do Try using the php mcrypt function instead, that might work. Mcrypt and and openssl_encrypt will return different results, even when using the same encryption methods as they work slightly differently. Compare the output of the ASP function to the results of the two methods in PHP and see if one of them returns the same results.

Equivalent of spongycastle encryption for ios


Tag : android , By : platformNomad
Date : March 29 2020, 07:55 AM
hop of those help? Right, I have had to scrap the encryption algorithm on the Android side, which posed a challenge, to find one that is cross-platform compatible.
I have read up a lot about Rob Napier's RNCryptor, and after googling for an Android equivalent, in which I found JNCryptor , I took the plunge and employed RNCryptor on the iOS side.

C# encryption (AesManaged) to PHP equivalent


Tag : chash , By : Lars
Date : March 29 2020, 07:55 AM
I wish this help you I have some data provided by our third party which is encrypted using a C# algorithm. Please see below: , We have figured out as below. I hope it would be useful for someone.
function encrypt($string = '', $key = '') {
    $key = utf8_encode($key);

    //make it 32 chars long. pad with \0 for shorter keys
    $key = str_pad($key, 32, "\0");

    //make the input string length multiples of 16. This is necessary
    $padding = 16 - (strlen($string) % 16);
    $string .= str_repeat(chr($padding), $padding);

    //emtpy IV - initialization vector
    $iv = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";

    $encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $string, MCRYPT_MODE_CBC, $iv));
    return rtrim($encrypted);
}

function decrypt($string = '', $key = '') {
    $key = $key . "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
    $iv = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
    $string = base64_decode($string);

    return mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $string, MCRYPT_MODE_CBC, $iv);
}

Java equivalent of C# AES encryption


Tag : java , By : waarg
Date : March 29 2020, 07:55 AM
around this issue You're initializing byte[] array = new byte[toEncrypt.length]; for some reason, but you never write the contents of toEncrypt into it before encryption. You could use System.arraycopy(toEncrypt, 0, array, 0, array.length);, but it would be easier to just use
byte[] array;
...
array = cipher.doFinal(toEncrypt);
...
return array;

PHP equivalent of .net AES encryption


Tag : chash , By : 3NZ0
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
  • In IE11 background colors not working on printing
  • TypeScript interface signature "(): string"
  • Is synchronous XMLHttpRequest supported in Internet Explorer 10 and 11?
  • Axios function not returning any values with js
  • How to use firestore TIMESTAMP to create time-stamp in JavaScript
  • Instantiate subclass without constructing
  • Outputing a created object in javascript to a server side JSON file
  • Transition the numeric labels in a bar chart
  • createBottomTabNavigator: hide just one tab from the tabBar
  • iife vs simple statement behavior with document.title
  • showDialogPopup Refresh Page after Click
  • Child component does not set the initial value passed from the parent: ReactJS
  • Nodejs javascript added to button not responding
  • Trying to define a promise.all
  • Python GEE to extract featurecollection timeseries from Landsat imageries
  • How to write negative binary number?
  • Unable to set property of individual object
  • Why Named Function Expression itself cannot assign Name to another Value?
  • How to reset scroll position on single page pagination
  • How to scroll to bottom of page, when a new message is sent - Socket.io
  • How to reconstruct audio blob from a base64 encoded String?
  • How to calculate numbers within an array of objects
  • Using JavaScript to change CSS properties of SVG circles for all circles that was not clicked
  • Is there value in propTypeing repeat required properties at every level of nested components?
  • Call function if variable does not exist in a filter
  • localStorage value doesn't get updated automatically
  • React not updating state with setState correctly inside promises
  • Direct native JavaScript or jQuery method to get containing block of an element
  • Dynamic JSON object to Html Table
  • How to send Id and file to same controller?
  • How to Make a jQuery Table Cell(td) clickable to Run a Function?
  • Prevent the duplicate function onchange event jQuery
  • Reactjs Input Upload doesn't return local URL
  • An unexpected 'StartObject' node was found when reading from the JSON reader. A 'PrimitiveValue' node was expected
  • How to filter a JSON Array, with an eventListener input value at keyup
  • How to separate the different properties of filter in css?
  • Why dont work change event of bootstrap input spinner?
  • How to hide overflow text content in react
  • Is there another way to write line 6
  • Cypress - how to find by text content?
  • How to setstate for the dynamic checkboxes in a loop in react?
  • Is display:none safe?
  • How to create a form to change part of a href url of a button?
  • Put many function inside function in Javascript
  • how to exit from loop after a ajax call
  • Do Angular Reactive Form Validator.min/max check Perform Type Conversions before checking the value?
  • How to Replace Text Within Script Tags Using JQuery
  • add variable to object if not undefined using short-hand
  • How can I effectively curve my items inside a list?
  • Add new record Keyboard Shortcut on Kendo Grid Mvc
  • Time and Date running on page
  • Looping through page links puppeteer doesn't return values from the newly loaded page
  • Problem with Navigator.geoLocation.getCurrentPosition not working
  • Trying to change the id of an element with Javascript
  • Embedded Schema Inserting Blank in Meteor using Collection2
  • avoid useEffect to render at first load?
  • Why is this CSS transition only working correctly on the some clicks? How to solve it?
  • Interpolated values does not reflect the latest values in an Angular app
  • Javascript classes define attribute in constructor or outside the class
  • How to block scroll event passing through to iframe until iframe is active?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com