org.whispersystems.util.Base64 Java Examples
The following examples show how to use
org.whispersystems.util.Base64.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SignalServiceMessageSender.java From libsignal-service-java with GNU General Public License v3.0 | 6 votes |
private void sendMessage(VerifiedMessage message, Optional<UnidentifiedAccessPair> unidentifiedAccess) throws IOException, UntrustedIdentityException { byte[] nullMessageBody = DataMessage.newBuilder() .setBody(Base64.encodeBytes(Util.getRandomLengthBytes(140))) .build() .toByteArray(); NullMessage nullMessage = NullMessage.newBuilder() .setPadding(ByteString.copyFrom(nullMessageBody)) .build(); byte[] content = Content.newBuilder() .setNullMessage(nullMessage) .build() .toByteArray(); SendMessageResult result = sendMessage(message.getDestination(), getTargetUnidentifiedAccess(unidentifiedAccess), message.getTimestamp(), content, false); if (result.getSuccess().isNeedsSync()) { byte[] syncMessage = createMultiDeviceVerifiedContent(message, nullMessage.toByteArray()); sendMessage(localAddress, Optional.<UnidentifiedAccess>absent(), message.getTimestamp(), syncMessage, false); } }
Example #2
Source File: ResumableUploadSpec.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
public static ResumableUploadSpec deserialize(String serializedSpec) throws ResumeLocationInvalidException { if (serializedSpec == null) return null; try { ResumableUploads.ResumableUpload resumableUpload = ResumableUploads.ResumableUpload.parseFrom(ByteString.copyFrom(Base64.decode(serializedSpec))); return new ResumableUploadSpec( resumableUpload.getSecretKey().toByteArray(), resumableUpload.getIv().toByteArray(), resumableUpload.getCdnKey(), resumableUpload.getCdnNumber(), resumableUpload.getLocation(), resumableUpload.getTimeout() ); } catch (IOException e) { throw new ResumeLocationInvalidException(); } }
Example #3
Source File: ServiceConfig.java From signal-cli with GNU General Public License v3.0 | 6 votes |
public static SignalServiceConfiguration createDefaultServiceConfiguration(String userAgent) { final Interceptor userAgentInterceptor = chain -> chain.proceed(chain.request().newBuilder() .header("User-Agent", userAgent) .build()); final List<Interceptor> interceptors = Collections.singletonList(userAgentInterceptor); final byte[] zkGroupServerPublicParams; try { zkGroupServerPublicParams = Base64.decode(zkGroupServerPublicParamsHex); } catch (IOException e) { throw new AssertionError(e); } return new SignalServiceConfiguration( new SignalServiceUrl[]{new SignalServiceUrl(URL, TRUST_STORE)}, makeSignalCdnUrlMapFor(new SignalCdnUrl[]{new SignalCdnUrl(CDN_URL, TRUST_STORE)}, new SignalCdnUrl[]{new SignalCdnUrl(CDN2_URL, TRUST_STORE)}), new SignalContactDiscoveryUrl[0], new SignalKeyBackupServiceUrl[]{new SignalKeyBackupServiceUrl(SIGNAL_KEY_BACKUP_URL, TRUST_STORE)}, new SignalStorageUrl[]{new SignalStorageUrl(STORAGE_URL, TRUST_STORE)}, interceptors, dns, zkGroupServerPublicParams ); }
Example #4
Source File: JsonSessionStore.java From signal-cli with GNU General Public License v3.0 | 6 votes |
@Override public void serialize(JsonSessionStore jsonSessionStore, JsonGenerator json, SerializerProvider serializerProvider) throws IOException { json.writeStartArray(); for (SessionInfo sessionInfo : jsonSessionStore.sessions) { json.writeStartObject(); if (sessionInfo.address.getNumber().isPresent()) { json.writeStringField("name", sessionInfo.address.getNumber().get()); } if (sessionInfo.address.getUuid().isPresent()) { json.writeStringField("uuid", sessionInfo.address.getUuid().get().toString()); } json.writeNumberField("deviceId", sessionInfo.deviceId); json.writeStringField("record", Base64.encodeBytes(sessionInfo.sessionRecord)); json.writeEndObject(); } json.writeEndArray(); }
Example #5
Source File: JsonIdentityKeyStore.java From signal-cli with GNU General Public License v3.0 | 6 votes |
@Override public void serialize(JsonIdentityKeyStore jsonIdentityKeyStore, JsonGenerator json, SerializerProvider serializerProvider) throws IOException { json.writeStartObject(); json.writeNumberField("registrationId", jsonIdentityKeyStore.getLocalRegistrationId()); json.writeStringField("identityKey", Base64.encodeBytes(jsonIdentityKeyStore.getIdentityKeyPair().serialize())); json.writeArrayFieldStart("trustedKeys"); for (Identity trustedKey : jsonIdentityKeyStore.identities) { json.writeStartObject(); if (trustedKey.getAddress().getNumber().isPresent()) { json.writeStringField("name", trustedKey.getAddress().getNumber().get()); } if (trustedKey.getAddress().getUuid().isPresent()) { json.writeStringField("uuid", trustedKey.getAddress().getUuid().get().toString()); } json.writeStringField("identityKey", Base64.encodeBytes(trustedKey.identityKey.serialize())); json.writeNumberField("trustLevel", trustedKey.trustLevel.ordinal()); json.writeNumberField("addedTimestamp", trustedKey.added.getTime()); json.writeEndObject(); } json.writeEndArray(); json.writeEndObject(); }
Example #6
Source File: JsonSignedPreKeyStore.java From signal-cli with GNU General Public License v3.0 | 6 votes |
@Override public JsonSignedPreKeyStore deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { JsonNode node = jsonParser.getCodec().readTree(jsonParser); Map<Integer, byte[]> preKeyMap = new HashMap<>(); if (node.isArray()) { for (JsonNode preKey : node) { Integer preKeyId = preKey.get("id").asInt(); try { preKeyMap.put(preKeyId, Base64.decode(preKey.get("record").asText())); } catch (IOException e) { System.out.println(String.format("Error while decoding prekey for: %s", preKeyId)); } } } JsonSignedPreKeyStore keyStore = new JsonSignedPreKeyStore(); keyStore.addSignedPreKeys(preKeyMap); return keyStore; }
Example #7
Source File: JsonPreKeyStore.java From signal-cli with GNU General Public License v3.0 | 6 votes |
@Override public JsonPreKeyStore deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { JsonNode node = jsonParser.getCodec().readTree(jsonParser); Map<Integer, byte[]> preKeyMap = new HashMap<>(); if (node.isArray()) { for (JsonNode preKey : node) { Integer preKeyId = preKey.get("id").asInt(); try { preKeyMap.put(preKeyId, Base64.decode(preKey.get("record").asText())); } catch (IOException e) { System.out.println(String.format("Error while decoding prekey for: %s", preKeyId)); } } } JsonPreKeyStore keyStore = new JsonPreKeyStore(); keyStore.addPreKeys(preKeyMap); return keyStore; }
Example #8
Source File: SignalServiceMessageSender.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
private void sendMessage(VerifiedMessage message, Optional<UnidentifiedAccessPair> unidentifiedAccess) throws IOException, UntrustedIdentityException { byte[] nullMessageBody = DataMessage.newBuilder() .setBody(Base64.encodeBytes(Util.getRandomLengthBytes(140))) .build() .toByteArray(); NullMessage nullMessage = NullMessage.newBuilder() .setPadding(ByteString.copyFrom(nullMessageBody)) .build(); byte[] content = Content.newBuilder() .setNullMessage(nullMessage) .build() .toByteArray(); SendMessageResult result = sendMessage(message.getDestination(), getTargetUnidentifiedAccess(unidentifiedAccess), message.getTimestamp(), content, false); if (result.getSuccess().isNeedsSync()) { byte[] syncMessage = createMultiDeviceVerifiedContent(message, nullMessage.toByteArray()); sendMessage(localAddress, Optional.<UnidentifiedAccess>absent(), message.getTimestamp(), syncMessage, false); } }
Example #9
Source File: Manager.java From signal-cli with GNU General Public License v3.0 | 5 votes |
private static SignalProfile decryptProfile(SignalServiceProfile encryptedProfile, ProfileKey profileKey) throws IOException { ProfileCipher profileCipher = new ProfileCipher(profileKey); try { return new SignalProfile( encryptedProfile.getIdentityKey(), encryptedProfile.getName() == null ? null : new String(profileCipher.decryptName(Base64.decode(encryptedProfile.getName()))), encryptedProfile.getAvatar(), encryptedProfile.getUnidentifiedAccess() == null || !profileCipher.verifyUnidentifiedAccess(Base64.decode(encryptedProfile.getUnidentifiedAccess())) ? null : encryptedProfile.getUnidentifiedAccess(), encryptedProfile.isUnrestrictedUnidentifiedAccess() ); } catch (InvalidCiphertextException e) { return null; } }
Example #10
Source File: Utils.java From signal-cli with GNU General Public License v3.0 | 5 votes |
static CertificateValidator getCertificateValidator() { try { ECPublicKey unidentifiedSenderTrustRoot = Curve.decodePoint(Base64.decode(ServiceConfig.UNIDENTIFIED_SENDER_TRUST_ROOT), 0); return new CertificateValidator(unidentifiedSenderTrustRoot); } catch (InvalidKeyException | IOException e) { throw new AssertionError(e); } }
Example #11
Source File: Utils.java From signal-cli with GNU General Public License v3.0 | 5 votes |
static String createDeviceLinkUri(DeviceLinkInfo info) { try { return "tsdevice:/?uuid=" + URLEncoder.encode(info.deviceIdentifier, "utf-8") + "&pub_key=" + URLEncoder.encode(Base64.encodeBytesWithoutPadding(info.deviceKey.serialize()), "utf-8"); } catch (UnsupportedEncodingException e) { // Shouldn't happen return null; } }
Example #12
Source File: SignalServiceMessagePipe.java From libsignal-service-java with GNU General Public License v3.0 | 5 votes |
public SignalServiceProfile getProfile(SignalServiceAddress address, Optional<UnidentifiedAccess> unidentifiedAccess) throws IOException { try { List<String> headers = new LinkedList<>(); if (unidentifiedAccess.isPresent()) { headers.add("Unidentified-Access-Key:" + Base64.encodeBytes(unidentifiedAccess.get().getUnidentifiedAccessKey())); } WebSocketRequestMessage requestMessage = WebSocketRequestMessage.newBuilder() .setId(SecureRandom.getInstance("SHA1PRNG").nextLong()) .setVerb("GET") .setPath(String.format("/v1/profile/%s", address.getIdentifier())) .addAllHeaders(headers) .build(); Pair<Integer, String> response = websocket.sendRequest(requestMessage).get(10, TimeUnit.SECONDS); if (response.first() < 200 || response.first() >= 300) { throw new IOException("Non-successful response: " + response.first()); } return JsonUtil.fromJson(response.second(), SignalServiceProfile.class); } catch (NoSuchAlgorithmException nsae) { throw new AssertionError(nsae); } catch (InterruptedException | ExecutionException | TimeoutException e) { throw new IOException(e); } }
Example #13
Source File: Utils.java From signal-cli with GNU General Public License v3.0 | 5 votes |
static DeviceLinkInfo parseDeviceLinkUri(URI linkUri) throws IOException, InvalidKeyException { Map<String, String> query = getQueryMap(linkUri.getRawQuery()); String deviceIdentifier = query.get("uuid"); String publicKeyEncoded = query.get("pub_key"); if (isEmpty(deviceIdentifier) || isEmpty(publicKeyEncoded)) { throw new RuntimeException("Invalid device link uri"); } ECPublicKey deviceKey = Curve.decodePoint(Base64.decode(publicKeyEncoded), 0); return new DeviceLinkInfo(deviceIdentifier, deviceKey); }
Example #14
Source File: JsonGroupStore.java From signal-cli with GNU General Public License v3.0 | 5 votes |
@Override public Map<String, GroupInfo> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { Map<String, GroupInfo> groups = new HashMap<>(); JsonNode node = jsonParser.getCodec().readTree(jsonParser); for (JsonNode n : node) { GroupInfo g = jsonProcessor.treeToValue(n, GroupInfo.class); // Check if a legacy avatarId exists if (g.getAvatarId() != 0) { groupsWithLegacyAvatarId.add(g); } groups.put(Base64.encodeBytes(g.groupId), g); } return groups; }
Example #15
Source File: JsonSessionStore.java From signal-cli with GNU General Public License v3.0 | 5 votes |
@Override public JsonSessionStore deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { JsonNode node = jsonParser.getCodec().readTree(jsonParser); JsonSessionStore sessionStore = new JsonSessionStore(); if (node.isArray()) { for (JsonNode session : node) { String sessionName = session.has("name") ? session.get("name").asText() : null; if (UuidUtil.isUuid(sessionName)) { // Ignore sessions that were incorrectly created with UUIDs as name continue; } UUID uuid = session.hasNonNull("uuid") ? UuidUtil.parseOrNull(session.get("uuid").asText()) : null; final SignalServiceAddress serviceAddress = uuid == null ? Util.getSignalServiceAddressFromIdentifier(sessionName) : new SignalServiceAddress(uuid, sessionName); final int deviceId = session.get("deviceId").asInt(); final String record = session.get("record").asText(); try { SessionInfo sessionInfo = new SessionInfo(serviceAddress, deviceId, Base64.decode(record)); sessionStore.sessions.add(sessionInfo); } catch (IOException e) { System.out.println(String.format("Error while decoding session for: %s", sessionName)); } } } return sessionStore; }
Example #16
Source File: JsonSignedPreKeyStore.java From signal-cli with GNU General Public License v3.0 | 5 votes |
@Override public void serialize(JsonSignedPreKeyStore jsonPreKeyStore, JsonGenerator json, SerializerProvider serializerProvider) throws IOException { json.writeStartArray(); for (Map.Entry<Integer, byte[]> signedPreKey : jsonPreKeyStore.store.entrySet()) { json.writeStartObject(); json.writeNumberField("id", signedPreKey.getKey()); json.writeStringField("record", Base64.encodeBytes(signedPreKey.getValue())); json.writeEndObject(); } json.writeEndArray(); }
Example #17
Source File: JsonPreKeyStore.java From signal-cli with GNU General Public License v3.0 | 5 votes |
@Override public void serialize(JsonPreKeyStore jsonPreKeyStore, JsonGenerator json, SerializerProvider serializerProvider) throws IOException { json.writeStartArray(); for (Map.Entry<Integer, byte[]> preKey : jsonPreKeyStore.store.entrySet()) { json.writeStartObject(); json.writeNumberField("id", preKey.getKey()); json.writeStringField("record", Base64.encodeBytes(preKey.getValue())); json.writeEndObject(); } json.writeEndArray(); }
Example #18
Source File: SignalAccount.java From signal-cli with GNU General Public License v3.0 | 5 votes |
public void save() { if (fileChannel == null) { return; } ObjectNode rootNode = jsonProcessor.createObjectNode(); rootNode.put("username", username) .put("uuid", uuid == null ? null : uuid.toString()) .put("deviceId", deviceId) .put("isMultiDevice", isMultiDevice) .put("password", password) .put("registrationLockPin", registrationLockPin) .put("signalingKey", signalingKey) .put("preKeyIdOffset", preKeyIdOffset) .put("nextSignedPreKeyId", nextSignedPreKeyId) .put("profileKey", Base64.encodeBytes(profileKey.serialize())) .put("registered", registered) .putPOJO("axolotlStore", signalProtocolStore) .putPOJO("groupStore", groupStore) .putPOJO("contactStore", contactStore) .putPOJO("recipientStore", recipientStore) ; try { synchronized (fileChannel) { fileChannel.position(0); jsonProcessor.writeValue(Channels.newOutputStream(fileChannel), rootNode); fileChannel.truncate(fileChannel.position()); fileChannel.force(false); } } catch (Exception e) { System.err.println(String.format("Error saving file: %s", e.getMessage())); } }
Example #19
Source File: JsonGroupInfo.java From signal-cli with GNU General Public License v3.0 | 5 votes |
JsonGroupInfo(SignalServiceGroup groupInfo) { this.groupId = Base64.encodeBytes(groupInfo.getGroupId()); if (groupInfo.getMembers().isPresent()) { this.members = new ArrayList<>(groupInfo.getMembers().get().size()); for (SignalServiceAddress address : groupInfo.getMembers().get()) { this.members.add(address.getNumber().get()); } } if (groupInfo.getName().isPresent()) { this.name = groupInfo.getName().get(); } this.type = groupInfo.getType().toString(); }
Example #20
Source File: Util.java From signal-cli with GNU General Public License v3.0 | 5 votes |
public static byte[] decodeGroupId(String groupId) throws GroupIdFormatException { try { return Base64.decode(groupId); } catch (IOException e) { throw new GroupIdFormatException(groupId, e); } }
Example #21
Source File: Manager.java From signal-cli with GNU General Public License v3.0 | 5 votes |
public void setGroupBlocked(final byte[] groupId, final boolean blocked) throws GroupNotFoundException { GroupInfo group = getGroup(groupId); if (group == null) { throw new GroupNotFoundException(groupId); } else { System.err.println((blocked ? "Blocking" : "Unblocking") + " group " + Base64.encodeBytes(groupId)); group.blocked = blocked; account.getGroupStore().updateGroup(group); account.save(); } }
Example #22
Source File: ListGroupsCommand.java From signal-cli with GNU General Public License v3.0 | 5 votes |
private static void printGroup(GroupInfo group, boolean detailed, SignalServiceAddress address) { if (detailed) { System.out.println(String.format("Id: %s Name: %s Active: %s Blocked: %b Members: %s", Base64.encodeBytes(group.groupId), group.name, group.isMember(address), group.blocked, group.getMembersE164())); } else { System.out.println(String.format("Id: %s Name: %s Active: %s Blocked: %b", Base64.encodeBytes(group.groupId), group.name, group.isMember(address), group.blocked)); } }
Example #23
Source File: SigningCertificateTest.java From libsignal-service-java with GNU General Public License v3.0 | 5 votes |
public void testBadSignature() throws CertificateException, NoSuchAlgorithmException, IOException, KeyStoreException, CertPathValidatorException, SignatureException { String certificateChain = "-----BEGIN%20CERTIFICATE-----%0AMIIEoTCCAwmgAwIBAgIJANEHdl0yo7CWMA0GCSqGSIb3DQEBCwUAMH4xCzAJBgNV%0ABAYTAlVTMQswCQYDVQQIDAJDQTEUMBIGA1UEBwwLU2FudGEgQ2xhcmExGjAYBgNV%0ABAoMEUludGVsIENvcnBvcmF0aW9uMTAwLgYDVQQDDCdJbnRlbCBTR1ggQXR0ZXN0%0AYXRpb24gUmVwb3J0IFNpZ25pbmcgQ0EwHhcNMTYxMTIyMDkzNjU4WhcNMjYxMTIw%0AMDkzNjU4WjB7MQswCQYDVQQGEwJVUzELMAkGA1UECAwCQ0ExFDASBgNVBAcMC1Nh%0AbnRhIENsYXJhMRowGAYDVQQKDBFJbnRlbCBDb3Jwb3JhdGlvbjEtMCsGA1UEAwwk%0ASW50ZWwgU0dYIEF0dGVzdGF0aW9uIFJlcG9ydCBTaWduaW5nMIIBIjANBgkqhkiG%0A9w0BAQEFA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VzWh5aiEx%2BidkSGMnX%0A-----END%20CERTIFICATE-----%0A"; String signature = "Kn2Ya2T039qvEWIzIQeSksNyyCQIkcVjciClcp3a6C766dJANXxLLIn6CfyvUZddMtePrTOLpC2e5QTQxB4RwtWmFfr7nxRdFUtA3dH2DAQL5DqqlmPv46ZWSPfiiOXUsu8vNgX3Z4Znt4Q+dIPIquNPY8ZmiAcpKR7n2K3QtabgOnJ2EyngabY3LMQTtriXbZjpl53ynhVhV1rciMdvMaTz4DUYt7gKi+KeNd3CBFSev+eTgYPC3em96J/3bfVR+wC5m3JGbIBCrwAsbO05JkiNIMck3s+p4d/hwiABR75EplxaWmGgIm6VvUKtGhdJ/cNrmF0nxMX6Vi6N2WaLTA=="; String signatureBody = "{\"id\":\"287419896494669543891634765983074535548\",\"timestamp\":\"2019-03-11T20:01:21.658293\",\"version\":3,\"isvEnclaveQuoteStatus\":\"OK\",\"isvEnclaveQuoteBody\":\"AgAAADILAAAIAAcAAAAAAPiLWcRSSA3shraxepsGV9qF4zYUPJgE42ZZZXS2G9zaBQUCBP//AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAAAAAAHAAAAAAAAAM1s/DQpN7I7G907v5chqlYVrJ/1CnXFUn1EHNMnaCbJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADrzm117Qj8NlEllyDkV4Pae4UgsPjgVXtAA5UsG90gVgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACHgz6GaO6bkxfPLBYcR5rEf9Itrt81OEanXteSMcd/BQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"}"; KeyStore keyStore = KeyStore.getInstance("JKS"); keyStore.load(getClass().getResourceAsStream("/ias.jks"), "whisper".toCharArray()); SigningCertificate certificate = new SigningCertificate(certificateChain, keyStore); byte[] decodedSignature = Base64.decode(signature); for (int i=0;i<signature.length();i++) { for (int j=0;i<8;i++) { byte[] malformedSignature = new byte[decodedSignature.length]; System.arraycopy(decodedSignature, 0, malformedSignature, 0, decodedSignature.length); malformedSignature[i] ^= (0x01 << j); try { certificate.verifySignature(signatureBody, Base64.encodeBytes(malformedSignature)); throw new AssertionError("Signature verification should fail!"); } catch (SignatureException e) { // good } } } }
Example #24
Source File: JsonUtil.java From libsignal-service-java with GNU General Public License v3.0 | 5 votes |
@Override public IdentityKey deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { try { return new IdentityKey(Base64.decodeWithoutPadding(p.getValueAsString()), 0); } catch (InvalidKeyException e) { throw new IOException(e); } }
Example #25
Source File: PreKeyEntity.java From libsignal-service-java with GNU General Public License v3.0 | 5 votes |
@Override public ECPublicKey deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { try { return Curve.decodePoint(Base64.decodeWithoutPadding(p.getValueAsString()), 0); } catch (InvalidKeyException e) { throw new IOException(e); } }
Example #26
Source File: PushServiceSocket.java From libsignal-service-java with GNU General Public License v3.0 | 5 votes |
private String getAuthorizationHeader(CredentialsProvider credentialsProvider) { try { String identifier = credentialsProvider.getUuid() != null ? credentialsProvider.getUuid().toString() : credentialsProvider.getE164(); return "Basic " + Base64.encodeBytes((identifier + ":" + credentialsProvider.getPassword()).getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new AssertionError(e); } }
Example #27
Source File: SigningCertificate.java From libsignal-service-java with GNU General Public License v3.0 | 5 votes |
public void verifySignature(String body, String encodedSignature) throws SignatureException { try { Signature signature = Signature.getInstance("SHA256withRSA"); signature.initVerify(path.getCertificates().get(0)); signature.update(body.getBytes()); if (!signature.verify(Base64.decode(encodedSignature.getBytes()))) { throw new SignatureException("Signature verification failed."); } } catch (NoSuchAlgorithmException | InvalidKeyException e) { throw new AssertionError(e); } }
Example #28
Source File: SignalServiceAccountManager.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public void setProfileName(ProfileKey key, String name) throws IOException { if (FeatureFlags.DISALLOW_OLD_PROFILE_SETTING) { throw new AssertionError(); } if (name == null) name = ""; String ciphertextName = Base64.encodeBytesWithoutPadding(new ProfileCipher(key).encryptName(name.getBytes(StandardCharsets.UTF_8), ProfileCipher.NAME_PADDED_LENGTH)); this.pushServiceSocket.setProfileName(ciphertextName); }
Example #29
Source File: SignalServiceEnvelope.java From libsignal-service-java with GNU General Public License v3.0 | 5 votes |
private SecretKeySpec getMacKey(String signalingKey) throws IOException { byte[] signalingKeyBytes = Base64.decode(signalingKey); byte[] macKey = new byte[MAC_KEY_SIZE]; System.arraycopy(signalingKeyBytes, CIPHER_KEY_SIZE, macKey, 0, macKey.length); return new SecretKeySpec(macKey, "HmacSHA256"); }
Example #30
Source File: SignalServiceEnvelope.java From libsignal-service-java with GNU General Public License v3.0 | 5 votes |
private SecretKeySpec getCipherKey(String signalingKey) throws IOException { byte[] signalingKeyBytes = Base64.decode(signalingKey); byte[] cipherKey = new byte[CIPHER_KEY_SIZE]; System.arraycopy(signalingKeyBytes, 0, cipherKey, 0, cipherKey.length); return new SecretKeySpec(cipherKey, "AES"); }