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?
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
|
show 3 more comments
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
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 sureaesjs.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
|
show 3 more comments
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
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
c# node.js aes
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 sureaesjs.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
|
show 3 more comments
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 sureaesjs.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
|
show 3 more comments
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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