Not an expert at this, but NSASCIIStringEncoding
seems to imply that you want data
and secret
interpreted as ASCII, whereas String.getBytes()
uses the default character set by default (i.e. UTF-8).
You probably need to use a different charset:
data.getBytes(StandardCharsets.US_ASCII);
secret.getBytes(StandardCharsets.US_ASCII);
For Java pre-1.7, you'll need to use this and catch the UnsupportedEncodingException
:
data.getBytes("US-ASCII");
secret.getBytes("US-ASCII");