As part of a project I'm working on i need to encrypt some data with AES in C#-code and decrypt it in Java. Since security isn't a top priority (this is just a proof of concept) we are ok with the key being stored in the code as a property in some class.
The question then is: since java and C# bytes are different, how do i store the key in both languages in a cut-n-pasteable way?
This is how i do now:
Java:
// aesKeyBytes.length = 32
private static byte[] aesKeyBytes = new byte[]{ 5, -67, 39 ... ,57, 120 }
C#:
private static byte[] KeyBytes() {
var sbytes = new sbyte[] { 5, -67, 39 ... ,57, 120 }
};
return = sbytes
.Select(sb => unchecked((byte) sb))
.ToArray();
}
Is this a correct way to do it? Is an sbyte semantically the same as a Java byte and will an unchecked conversion of an sbyte get the correct corresponding byte for my key?