Verifies that the signature from the server matches the computed signature on the data. Returns true if the data is correctly signed. @param publicKey public key associated with the developer account @param signedData signed data from server @param signature server signature @return true if the da
(PublicKey publicKey, String signedData, String signature)
| 220 | * @return true if the data and signature match |
| 221 | */ |
| 222 | public static boolean verify(PublicKey publicKey, String signedData, String signature) { |
| 223 | if (Consts.DEBUG) { |
| 224 | Log.i(TAG, "signature: " + signature); |
| 225 | } |
| 226 | Signature sig; |
| 227 | try { |
| 228 | sig = Signature.getInstance(SIGNATURE_ALGORITHM); |
| 229 | sig.initVerify(publicKey); |
| 230 | sig.update(signedData.getBytes()); |
| 231 | if (!sig.verify(Base64.decode(signature))) { |
| 232 | Log.e(TAG, "Signature verification failed."); |
| 233 | return false; |
| 234 | } |
| 235 | return true; |
| 236 | } catch (NoSuchAlgorithmException e) { |
| 237 | Log.e(TAG, "NoSuchAlgorithmException."); |
| 238 | } catch (InvalidKeyException e) { |
| 239 | Log.e(TAG, "Invalid key specification."); |
| 240 | } catch (SignatureException e) { |
| 241 | Log.e(TAG, "Signature exception."); |
| 242 | } catch (Base64DecoderException e) { |
| 243 | Log.e(TAG, "Base64 decoding failed."); |
| 244 | } |
| 245 | return false; |
| 246 | } |
| 247 | } |
no test coverage detected