Android Sign Data with P12 Certificate

So, I searched for a while and could not find what I needed (since every result that comes up concerns signing the actual package). So basically what I am doing is that WebServices are protected by the session manager, and in order to get the session number, the GUID needs to be sent to the WebService. On the iOS side, we were able to get this setting (because the team that developed WebService had an iOS developer there), but since none of this team or she has much experience with Android, they struggled to figure out how to do the same the most. Below I have tried so far, but the generated GUID consists of some strange characters and does not work, so I am stuck while I keep looking for other options.

        String password = "password";
        String text = "545048";
        KeyStore keyStore = KeyStore.getInstance("pkcs12");
        InputStream inputStream = activity.getResources().openRawResource(R.raw.am_client);
        keyStore.load(inputStream, password.toCharArray());

        String alias = keyStore.aliases().nextElement();
        PrivateKey privateKey = (PrivateKey)keyStore.getKey(alias, password.toCharArray());
        X509Certificate certificate = (X509Certificate)keyStore.getCertificate(alias);

        //Sign Data
        byte[] dataToSign = text.getBytes("UTF-8");
        Signature signature1 = Signature.getInstance("SHA1WithRSA");
        signature1.initSign(privateKey);
        signature1.update(dataToSign);
        byte[] signedData = signature1.sign();
        String signed = new String(signedData, "UTF-8");
        Log.d("MESSAGE", "string = " + signed);
        //This is what comes up in the Log:   m(N   xp r   K V>G3b   M  W08   6# ͞ + / ] , o   N" $  uVa ƾ ~  
+3
1

, , , (UTF-8), (UTF-16LE). , .

+2

All Articles