Closed ar3balaji closed 3 years ago
I'm going to transfer this to discussions, since it's not a spec issue. If you want specific feedback, I'd recommend providing a minimal, reproducible example (https://stackoverflow.com/help/minimal-reproducible-example)
Trying to construct compact Jws and convert it into numeric encoding for Qr code. Keep getting Data too big for requested version eventhough compressed json size is less than 600 characters. Not sure what the mistake is
-- Jws creation JWSObject jwsObject = new JWSObject(new JWSHeader.Builder(JWSAlgorithm.ES256).customParam("zip", "DEF") .keyID("123").build(), new Payload(compressedJsonInByteArray)); jwsObject.sign(new ECDSASigner((ECPrivateKey) privKey)); String compactJWS = jwsObject.serialize();
String numericCompactJWS = getNumericString(compactJWS);
--qr code generation Map<EncodeHintType, Object> hints = new EnumMap<EncodeHintType, Object>(EncodeHintType.class); hints.put(EncodeHintType.QR_VERSION,22);
QRCodeWriter qrCodeWriter = new QRCodeWriter(); BitMatrix bitMatrix = qrCodeWriter.encode("shc:/" +numericCompactJWS, BarcodeFormat.QR_CODE, 400, 400, hints);
ByteArrayOutputStream pngOutputStream = new ByteArrayOutputStream(); MatrixToImageWriter.writeToStream(bitMatrix, "PNG", pngOutputStream); byte[] pngData = pngOutputStream.toByteArray(); String encodedfile = new String(Base64.encodeBase64(pngData), "UTF-8");
public static String getNumericString(String data) { StringBuilder sb = new StringBuilder(); char[] letters = data.toCharArray(); for (char ch : letters) { int currentVal = (int)ch - 45; if (currentVal < 10) { sb.append("0" + currentVal); } else { sb.append(currentVal);
}
} return sb.toString(); }