Compatibility between AesJS and C# System.Security.CryptographyHow do I calculate someone's age in C#?What is the difference between String and string in C#?Hidden Features of C#?Cast int to enum in C#How do you give a C# Auto-Property a default value?How do I enumerate an enum in C#?What are the correct version numbers for C#?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?What's the difference between dependencies, devDependencies and peerDependencies in npm package.json file?What's the difference between tilde(~) and caret(^) in package.json?

Do I need a multiple entry visa for a trip UK -> Sweden -> UK?

Mapping a list into a phase plot

Increase performance creating Mandelbrot set in python

Is it okay / does it make sense for another player to join a running game of Munchkin?

Opposite of a diet

Using parameter substitution on a Bash array

Are there any comparative studies done between Ashtavakra Gita and Buddhim?

Is there any reason not to eat food that's been dropped on the surface of the moon?

Hostile work environment after whistle-blowing on coworker and our boss. What do I do?

Greatest common substring

Is HostGator storing my password in plaintext?

Was the picture area of a CRT a parallelogram (instead of a true rectangle)?

What is the oldest known work of fiction?

Is expanding the research of a group into machine learning as a PhD student risky?

Why does John Bercow say “unlock” after reading out the results of a vote?

If you attempt to grapple an opponent that you are hidden from, do they roll at disadvantage?

Confused about a passage in Harry Potter y la piedra filosofal

when is out of tune ok?

Can I Retrieve Email Addresses from BCC?

Why Were Madagascar and New Zealand Discovered So Late?

Can a monster with multiattack use this ability if they are missing a limb?

Products and sum of cubes in Fibonacci

How does it work when somebody invests in my business?

How could Frankenstein get the parts for his _second_ creature?



Compatibility between AesJS and C# System.Security.Cryptography


How do I calculate someone's age in C#?What is the difference between String and string in C#?Hidden Features of C#?Cast int to enum in C#How do you give a C# Auto-Property a default value?How do I enumerate an enum in C#?What are the correct version numbers for C#?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?What's the difference between dependencies, devDependencies and peerDependencies in npm package.json file?What's the difference between tilde(~) and caret(^) in package.json?













0















I'm developing an application in NodeJS that consums a C# API. And I want to implement securized calls with AES. I'm using AesJS in NodeJS and System.Security.Cryptography in C#.



The C# part is used in other parts of the application and works correctly, so I'm guessing my error is in the NodeJS part.



The error is:




Invalid length for a Base-64 char array or string.




My code:



NodeJS



encryptData = function(data) 
var key = pbkdf2.pbkdf2Sync(config.aes.pass, config.aes.salt, 1, 128 / 8, null);
var dataBytes = aesjs.utils.utf8.toBytes(data);
var ivBytes = aesjs.utils.utf8.toBytes(config.aes.iv);
var aesOfb = new aesjs.ModeOfOperation.ofb(key, ivBytes);
var encryptedBytes = aesOfb.encrypt(dataBytes);
var encryptedHex = aesjs.utils.hex.fromBytes(encryptedBytes);

return encryptedHex;



C#



public static string DecodeAndDecrypt(string encrypted)

using (var csp = Aes.Create())

var d = GetCryptoTransform(csp, false);
byte[] output = Convert.FromBase64String(encrypted);
byte[] decryptedOutput = d.TransformFinalBlock(output, 0, output.Length);
string decypted = Encoding.UTF8.GetString(decryptedOutput);
return decypted;




The error happens in this line:




byte[] output = Convert.FromBase64String(encrypted);




UPDATE



In order to test what's commented, I added parse to base64 in NodeJS:



return Buffer.from(encryptedHex).toString('base64');


Now I'm getting one step ahead into:




byte[] decryptedOutput = d.TransformFinalBlock(output, 0, output.Length);




And it returns error:




The input data is not a complete block.











share|improve this question
























  • Can you add details about the exception you are getting ?

    – Manoj Choudhari
    Mar 8 at 9:43











  • It really doesn't say much more. I can post the StackTrace if you want.

    – Andrés Marotta
    Mar 8 at 9:45












  • I'm not sure aesjs.utils.hex.fromBytes() produces Base64 encoding - it just converts to hexadecimal which is not the same thing.

    – spodger
    Mar 8 at 10:23











  • It's the way documentation says it's used: npmjs.com/package/aes-js#ofb---output-feedback

    – Andrés Marotta
    Mar 8 at 10:46











  • That document makes no mention of Base64 encoding. In fact the example it gives shows the output"55e3af2638c560b4fdb9d26a630733ea60197ec23deb85b1f60f71f10409ce27" which is hex not Base64.

    – spodger
    Mar 8 at 10:50















0















I'm developing an application in NodeJS that consums a C# API. And I want to implement securized calls with AES. I'm using AesJS in NodeJS and System.Security.Cryptography in C#.



The C# part is used in other parts of the application and works correctly, so I'm guessing my error is in the NodeJS part.



The error is:




Invalid length for a Base-64 char array or string.




My code:



NodeJS



encryptData = function(data) 
var key = pbkdf2.pbkdf2Sync(config.aes.pass, config.aes.salt, 1, 128 / 8, null);
var dataBytes = aesjs.utils.utf8.toBytes(data);
var ivBytes = aesjs.utils.utf8.toBytes(config.aes.iv);
var aesOfb = new aesjs.ModeOfOperation.ofb(key, ivBytes);
var encryptedBytes = aesOfb.encrypt(dataBytes);
var encryptedHex = aesjs.utils.hex.fromBytes(encryptedBytes);

return encryptedHex;



C#



public static string DecodeAndDecrypt(string encrypted)

using (var csp = Aes.Create())

var d = GetCryptoTransform(csp, false);
byte[] output = Convert.FromBase64String(encrypted);
byte[] decryptedOutput = d.TransformFinalBlock(output, 0, output.Length);
string decypted = Encoding.UTF8.GetString(decryptedOutput);
return decypted;




The error happens in this line:




byte[] output = Convert.FromBase64String(encrypted);




UPDATE



In order to test what's commented, I added parse to base64 in NodeJS:



return Buffer.from(encryptedHex).toString('base64');


Now I'm getting one step ahead into:




byte[] decryptedOutput = d.TransformFinalBlock(output, 0, output.Length);




And it returns error:




The input data is not a complete block.











share|improve this question
























  • Can you add details about the exception you are getting ?

    – Manoj Choudhari
    Mar 8 at 9:43











  • It really doesn't say much more. I can post the StackTrace if you want.

    – Andrés Marotta
    Mar 8 at 9:45












  • I'm not sure aesjs.utils.hex.fromBytes() produces Base64 encoding - it just converts to hexadecimal which is not the same thing.

    – spodger
    Mar 8 at 10:23











  • It's the way documentation says it's used: npmjs.com/package/aes-js#ofb---output-feedback

    – Andrés Marotta
    Mar 8 at 10:46











  • That document makes no mention of Base64 encoding. In fact the example it gives shows the output"55e3af2638c560b4fdb9d26a630733ea60197ec23deb85b1f60f71f10409ce27" which is hex not Base64.

    – spodger
    Mar 8 at 10:50













0












0








0








I'm developing an application in NodeJS that consums a C# API. And I want to implement securized calls with AES. I'm using AesJS in NodeJS and System.Security.Cryptography in C#.



The C# part is used in other parts of the application and works correctly, so I'm guessing my error is in the NodeJS part.



The error is:




Invalid length for a Base-64 char array or string.




My code:



NodeJS



encryptData = function(data) 
var key = pbkdf2.pbkdf2Sync(config.aes.pass, config.aes.salt, 1, 128 / 8, null);
var dataBytes = aesjs.utils.utf8.toBytes(data);
var ivBytes = aesjs.utils.utf8.toBytes(config.aes.iv);
var aesOfb = new aesjs.ModeOfOperation.ofb(key, ivBytes);
var encryptedBytes = aesOfb.encrypt(dataBytes);
var encryptedHex = aesjs.utils.hex.fromBytes(encryptedBytes);

return encryptedHex;



C#



public static string DecodeAndDecrypt(string encrypted)

using (var csp = Aes.Create())

var d = GetCryptoTransform(csp, false);
byte[] output = Convert.FromBase64String(encrypted);
byte[] decryptedOutput = d.TransformFinalBlock(output, 0, output.Length);
string decypted = Encoding.UTF8.GetString(decryptedOutput);
return decypted;




The error happens in this line:




byte[] output = Convert.FromBase64String(encrypted);




UPDATE



In order to test what's commented, I added parse to base64 in NodeJS:



return Buffer.from(encryptedHex).toString('base64');


Now I'm getting one step ahead into:




byte[] decryptedOutput = d.TransformFinalBlock(output, 0, output.Length);




And it returns error:




The input data is not a complete block.











share|improve this question
















I'm developing an application in NodeJS that consums a C# API. And I want to implement securized calls with AES. I'm using AesJS in NodeJS and System.Security.Cryptography in C#.



The C# part is used in other parts of the application and works correctly, so I'm guessing my error is in the NodeJS part.



The error is:




Invalid length for a Base-64 char array or string.




My code:



NodeJS



encryptData = function(data) 
var key = pbkdf2.pbkdf2Sync(config.aes.pass, config.aes.salt, 1, 128 / 8, null);
var dataBytes = aesjs.utils.utf8.toBytes(data);
var ivBytes = aesjs.utils.utf8.toBytes(config.aes.iv);
var aesOfb = new aesjs.ModeOfOperation.ofb(key, ivBytes);
var encryptedBytes = aesOfb.encrypt(dataBytes);
var encryptedHex = aesjs.utils.hex.fromBytes(encryptedBytes);

return encryptedHex;



C#



public static string DecodeAndDecrypt(string encrypted)

using (var csp = Aes.Create())

var d = GetCryptoTransform(csp, false);
byte[] output = Convert.FromBase64String(encrypted);
byte[] decryptedOutput = d.TransformFinalBlock(output, 0, output.Length);
string decypted = Encoding.UTF8.GetString(decryptedOutput);
return decypted;




The error happens in this line:




byte[] output = Convert.FromBase64String(encrypted);




UPDATE



In order to test what's commented, I added parse to base64 in NodeJS:



return Buffer.from(encryptedHex).toString('base64');


Now I'm getting one step ahead into:




byte[] decryptedOutput = d.TransformFinalBlock(output, 0, output.Length);




And it returns error:




The input data is not a complete block.








c# node.js aes






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 11:12







Andrés Marotta

















asked Mar 8 at 9:41









Andrés MarottaAndrés Marotta

89212




89212












  • Can you add details about the exception you are getting ?

    – Manoj Choudhari
    Mar 8 at 9:43











  • It really doesn't say much more. I can post the StackTrace if you want.

    – Andrés Marotta
    Mar 8 at 9:45












  • I'm not sure aesjs.utils.hex.fromBytes() produces Base64 encoding - it just converts to hexadecimal which is not the same thing.

    – spodger
    Mar 8 at 10:23











  • It's the way documentation says it's used: npmjs.com/package/aes-js#ofb---output-feedback

    – Andrés Marotta
    Mar 8 at 10:46











  • That document makes no mention of Base64 encoding. In fact the example it gives shows the output"55e3af2638c560b4fdb9d26a630733ea60197ec23deb85b1f60f71f10409ce27" which is hex not Base64.

    – spodger
    Mar 8 at 10:50

















  • Can you add details about the exception you are getting ?

    – Manoj Choudhari
    Mar 8 at 9:43











  • It really doesn't say much more. I can post the StackTrace if you want.

    – Andrés Marotta
    Mar 8 at 9:45












  • I'm not sure aesjs.utils.hex.fromBytes() produces Base64 encoding - it just converts to hexadecimal which is not the same thing.

    – spodger
    Mar 8 at 10:23











  • It's the way documentation says it's used: npmjs.com/package/aes-js#ofb---output-feedback

    – Andrés Marotta
    Mar 8 at 10:46











  • That document makes no mention of Base64 encoding. In fact the example it gives shows the output"55e3af2638c560b4fdb9d26a630733ea60197ec23deb85b1f60f71f10409ce27" which is hex not Base64.

    – spodger
    Mar 8 at 10:50
















Can you add details about the exception you are getting ?

– Manoj Choudhari
Mar 8 at 9:43





Can you add details about the exception you are getting ?

– Manoj Choudhari
Mar 8 at 9:43













It really doesn't say much more. I can post the StackTrace if you want.

– Andrés Marotta
Mar 8 at 9:45






It really doesn't say much more. I can post the StackTrace if you want.

– Andrés Marotta
Mar 8 at 9:45














I'm not sure aesjs.utils.hex.fromBytes() produces Base64 encoding - it just converts to hexadecimal which is not the same thing.

– spodger
Mar 8 at 10:23





I'm not sure aesjs.utils.hex.fromBytes() produces Base64 encoding - it just converts to hexadecimal which is not the same thing.

– spodger
Mar 8 at 10:23













It's the way documentation says it's used: npmjs.com/package/aes-js#ofb---output-feedback

– Andrés Marotta
Mar 8 at 10:46





It's the way documentation says it's used: npmjs.com/package/aes-js#ofb---output-feedback

– Andrés Marotta
Mar 8 at 10:46













That document makes no mention of Base64 encoding. In fact the example it gives shows the output"55e3af2638c560b4fdb9d26a630733ea60197ec23deb85b1f60f71f10409ce27" which is hex not Base64.

– spodger
Mar 8 at 10:50





That document makes no mention of Base64 encoding. In fact the example it gives shows the output"55e3af2638c560b4fdb9d26a630733ea60197ec23deb85b1f60f71f10409ce27" which is hex not Base64.

– spodger
Mar 8 at 10:50












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55060457%2fcompatibility-between-aesjs-and-c-sharp-system-security-cryptography%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55060457%2fcompatibility-between-aesjs-and-c-sharp-system-security-cryptography%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived