这是对称密钥的正常格式/大小吗?

ojsjcaue  于 2021-07-08  发布在  Java
关注(0)|答案(0)|浏览(168)

此函数用于创建对称密钥和非对称密钥,然后使用公钥和对称密钥以及一些其他数据生成二维码:

private void initQRCode() {
            String qrString = "";
                try {
                    Random r = new Random();
                    KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
                    keyPairGenerator.initialize(256, new SecureRandom());
                    KeyPair keyPair = keyPairGenerator.generateKeyPair();

                    KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
                    keyGenerator.init(256); // for example
                    SecretKey secretKey = keyGenerator.generateKey();

                    byte [] pubBytes = keyPair.getPublic().getEncoded();
                    byte [] symBytes = secretKey.getEncoded();
                    String publicKey = android.util.Base64.encodeToString(pubBytes,0);
                    String symKey = android.util.Base64.encodeToString(symBytes,0);

                    long groupID =  r.nextLong();
                    int tutorID = r. nextInt();

                    System.out.println(publicKey);
                    System.out.println(symKey);
                    System.out.println(groupID);
                    System.out.println(tutorID);

                    qrString = publicKey + ":::" + symKey  + ":::" + groupID + ":::" + tutorID;

                }catch(NoSuchAlgorithmException e){
                    e.printStackTrace();
                }
               if(qrString != "") {
                   StringBuilder textToSend = new StringBuilder();
                   textToSend.append(qrString);
                   MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
                   try {
                       BitMatrix bitMatrix = multiFormatWriter.encode(textToSend.toString(), BarcodeFormat.QR_CODE, 600, 600);
                       BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
                       Bitmap bitmap = barcodeEncoder.createBitmap(bitMatrix);
                       imageView.setImageBitmap(bitmap);
                       imageView.setVisibility(View.VISIBLE);

                   } catch (WriterException e) {
                       e.printStackTrace();
                   }
               }
        }

最终二维码结果:mdwwdqyjkozihvcnaqebbqadkwawkaihak6saelqtffeggacuxh9gkmmqfxlvsck1s4aeymh9ast agmbaae=::/3akto5322klhltwvy490s6/rpxw1z0ga30+hkni64e=::2629194659936505759:::1529276565

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题