Java Code Examples for org.jivesoftware.smack.util.stringencoder.Base64#decode()
The following examples show how to use
org.jivesoftware.smack.util.stringencoder.Base64#decode() .
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: SASLMechanism.java From Smack with Apache License 2.0 | 6 votes |
/** * The server is challenging the SASL mechanism for the stanza he just sent. Send a * response to the server's challenge. * * @param challengeString a base64 encoded string representing the challenge. * @param finalChallenge true if this is the last challenge send by the server within the success stanza * @throws SmackSaslException if a SASL related error occurs. * @throws InterruptedException if the connection is interrupted * @throws NotConnectedException if the XMPP connection is not connected. */ public final void challengeReceived(String challengeString, boolean finalChallenge) throws SmackSaslException, InterruptedException, NotConnectedException { byte[] challenge = Base64.decode((challengeString != null && challengeString.equals("=")) ? "" : challengeString); byte[] response = evaluateChallenge(challenge); if (finalChallenge) { return; } Response responseStanza; if (response == null) { responseStanza = new Response(); } else { responseStanza = new Response(Base64.encodeToString(response)); } // Send the authentication to the server connection.sendNonza(responseStanza); }
Example 2
Source File: DataPacketExtension.java From Smack with Apache License 2.0 | 6 votes |
/** * Returns the decoded data or null if data could not be decoded. * <p> * The encoded data is invalid if it contains bad Base64 input characters or * if it contains the pad ('=') character on a position other than the last * character(s) of the data. See <a * href="http://xmpp.org/extensions/xep-0047.html#sec">XEP-0047</a> Section * 6. * * @return the decoded data */ public byte[] getDecodedData() { // return cached decoded data if (this.decodedData != null) { return this.decodedData; } // data must not contain the pad (=) other than end of data if (data.matches(".*={1,2}+.+")) { return null; } // decodeBase64 will return null if bad characters are included this.decodedData = Base64.decode(data); return this.decodedData; }
Example 3
Source File: OmemoBundleElement.java From Smack with Apache License 2.0 | 5 votes |
/** * Return the signedPreKey of the OmemoBundleElement. * * @return signedPreKey as byte array */ public byte[] getSignedPreKey() { if (signedPreKey == null) { signedPreKey = Base64.decode(signedPreKeyB64); } return this.signedPreKey.clone(); }
Example 4
Source File: OmemoBundleElement.java From Smack with Apache License 2.0 | 5 votes |
/** * Get the signature of the signedPreKey. * * @return signature as byte array */ public byte[] getSignedPreKeySignature() { if (signedPreKeySignature == null) { signedPreKeySignature = Base64.decode(signedPreKeySignatureB64); } return signedPreKeySignature.clone(); }
Example 5
Source File: SecretKeyBackupHelper.java From Smack with Apache License 2.0 | 5 votes |
/** * Decrypt a secret key backup and return the {@link PGPSecretKeyRing} contained in it. * TODO: Return a PGPSecretKeyRingCollection instead? * * @param backup encrypted {@link SecretkeyElement} containing the backup * @param backupCode passphrase for decrypting the {@link SecretkeyElement}. * @return the TODO javadoc me please * @throws InvalidBackupCodeException in case the provided backup code is invalid. * @throws IOException IO is dangerous. * @throws PGPException PGP is brittle. */ public static PGPSecretKeyRing restoreSecretKeyBackup(SecretkeyElement backup, String backupCode) throws InvalidBackupCodeException, IOException, PGPException { byte[] encrypted = Base64.decode(backup.getB64Data()); byte[] decrypted; try { decrypted = PGPainless.decryptWithPassword(encrypted, new Passphrase(backupCode.toCharArray())); } catch (IOException | PGPException e) { throw new InvalidBackupCodeException("Could not decrypt secret key backup. Possibly wrong passphrase?", e); } return PGPainless.readKeyRing().secretKeyRing(decrypted); }
Example 6
Source File: OmemoVAxolotlProvider.java From Smack with Apache License 2.0 | 4 votes |
@Override public OmemoElement_VAxolotl parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException { boolean inEncrypted = true; int sid = -1; ArrayList<OmemoKeyElement> keys = new ArrayList<>(); byte[] iv = null; byte[] payload = null; while (inEncrypted) { XmlPullParser.Event tag = parser.next(); String name = parser.getName(); switch (tag) { case START_ELEMENT: switch (name) { case OmemoHeaderElement.ELEMENT: for (int i = 0; i < parser.getAttributeCount(); i++) { if (parser.getAttributeName(i).equals(OmemoHeaderElement.ATTR_SID)) { sid = Integer.parseInt(parser.getAttributeValue(i)); } } break; case OmemoKeyElement.ELEMENT: boolean prekey = false; int rid = -1; for (int i = 0; i < parser.getAttributeCount(); i++) { if (parser.getAttributeName(i).equals(OmemoKeyElement.ATTR_PREKEY)) { prekey = Boolean.parseBoolean(parser.getAttributeValue(i)); } else if (parser.getAttributeName(i).equals(OmemoKeyElement.ATTR_RID)) { rid = Integer.parseInt(parser.getAttributeValue(i)); } } keys.add(new OmemoKeyElement(Base64.decode(parser.nextText()), rid, prekey)); break; case OmemoHeaderElement.ATTR_IV: iv = Base64.decode(parser.nextText()); break; case ATTR_PAYLOAD: payload = Base64.decode(parser.nextText()); break; } break; case END_ELEMENT: if (name.equals(NAME_ENCRYPTED)) { inEncrypted = false; } break; default: // Catch all for incomplete switch (MissingCasesInEnumSwitch) statement. break; } } OmemoHeaderElement_VAxolotl header = new OmemoHeaderElement_VAxolotl(sid, keys, iv); return new OmemoElement_VAxolotl(header, payload); }
Example 7
Source File: HashElement.java From Smack with Apache License 2.0 | 4 votes |
/** * Create a HashElement from pre-calculated values. * @param algorithm the algorithm that was used. * @param hashB64 the checksum in base 64. */ public HashElement(HashManager.ALGORITHM algorithm, String hashB64) { this.algorithm = algorithm; this.hash = Base64.decode(hashB64); this.hashB64 = hashB64; }
Example 8
Source File: DnsIq.java From Smack with Apache License 2.0 | 4 votes |
public DnsIq(String base64DnsMessage) throws IOException { this(Base64.decode(base64DnsMessage)); this.base64DnsMessage = base64DnsMessage; }
Example 9
Source File: PubkeyElement.java From Smack with Apache License 2.0 | 4 votes |
public byte[] getPubKeyBytes() { if (pubKeyBytesCache == null) { pubKeyBytesCache = Base64.decode(b64Data); } return pubKeyBytesCache.clone(); }
Example 10
Source File: SoundSettings.java From Smack with Apache License 2.0 | 4 votes |
public byte[] getIncomingSoundBytes() { return Base64.decode(incomingSound); }
Example 11
Source File: SoundSettings.java From Smack with Apache License 2.0 | 4 votes |
public byte[] getOutgoingSoundBytes() { return Base64.decode(outgoingSound); }
Example 12
Source File: JivePropertiesExtensionProvider.java From Smack with Apache License 2.0 | 4 votes |
/** * Parse a properties sub-packet. If any errors occur while de-serializing Java object * properties, an exception will be printed and not thrown since a thrown exception will shut * down the entire connection. ClassCastExceptions will occur when both the sender and receiver * of the stanza don't have identical versions of the same class. * <p> * Note that you have to explicitly enabled Java object deserialization with @{link * {@link JivePropertiesManager#setJavaObjectEnabled(boolean)} * * @param parser the XML parser, positioned at the start of a properties sub-packet. * @return a map of the properties. * @throws IOException if an I/O error occurred. * @throws XmlPullParserException if an error in the XML parser occurred. */ @Override public JivePropertiesExtension parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException { Map<String, Object> properties = new HashMap<>(); while (true) { XmlPullParser.Event eventType = parser.next(); if (eventType == XmlPullParser.Event.START_ELEMENT && parser.getName().equals("property")) { // Parse a property boolean done = false; String name = null; String type = null; String valueText = null; Object value = null; while (!done) { eventType = parser.next(); if (eventType == XmlPullParser.Event.START_ELEMENT) { String elementName = parser.getName(); if (elementName.equals("name")) { name = parser.nextText(); } else if (elementName.equals("value")) { type = parser.getAttributeValue("", "type"); valueText = parser.nextText(); } } else if (eventType == XmlPullParser.Event.END_ELEMENT) { if (parser.getName().equals("property")) { if ("integer".equals(type)) { value = Integer.valueOf(valueText); } else if ("long".equals(type)) { value = Long.valueOf(valueText); } else if ("float".equals(type)) { value = Float.valueOf(valueText); } else if ("double".equals(type)) { value = Double.valueOf(valueText); } else if ("boolean".equals(type)) { // CHECKSTYLE:OFF value = Boolean.valueOf(valueText); // CHECKSTYLE:ON } else if ("string".equals(type)) { value = valueText; } else if ("java-object".equals(type)) { if (JivePropertiesManager.isJavaObjectEnabled()) { try { byte[] bytes = Base64.decode(valueText); ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream(bytes)); value = in.readObject(); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Error parsing java object", e); } } else { LOGGER.severe("JavaObject is not enabled. Enable with JivePropertiesManager.setJavaObjectEnabled(true)"); } } if (name != null && value != null) { properties.put(name, value); } done = true; } } } } else if (eventType == XmlPullParser.Event.END_ELEMENT) { if (parser.getName().equals(JivePropertiesExtension.ELEMENT)) { break; } } } return new JivePropertiesExtension(properties); }
Example 13
Source File: VCardTest.java From Smack with Apache License 2.0 | 4 votes |
public static byte[] getAvatarBinary() { return Base64.decode(getAvatarEncoded()); }
Example 14
Source File: OmemoBundleElement.java From Smack with Apache License 2.0 | 3 votes |
/** * Return the public identityKey of the bundles owner. * This can be used to check the signedPreKeys signature. * The fingerprint of this key is, what the user has to verify. * * @return public identityKey as byte array */ public byte[] getIdentityKey() { if (identityKey == null) { identityKey = Base64.decode(identityKeyB64); } return this.identityKey.clone(); }
Example 15
Source File: VCard.java From Smack with Apache License 2.0 | 3 votes |
/** * Return the byte representation of the avatar(if one exists), otherwise returns null if * no avatar could be found. * <b>Example 1</b> * <pre> * // Load Avatar from VCard * byte[] avatarBytes = vCard.getAvatar(); * * // To create an ImageIcon for Swing applications * ImageIcon icon = new ImageIcon(avatar); * * // To create just an image object from the bytes * ByteArrayInputStream bais = new ByteArrayInputStream(avatar); * try { * Image image = ImageIO.read(bais); * } * catch (IOException e) { * e.printStackTrace(); * } * </pre> * * @return byte representation of avatar. */ public byte[] getAvatar() { if (photoBinval == null) { return null; } return Base64.decode(photoBinval); }