Search in sources :

Example 26 with Decoder

use of java.util.Base64.Decoder in project rpki-validator-3 by RIPE-NCC.

the class RrdpParser method snapshot.

public Snapshot snapshot(final InputStream inputStream) {
    final Map<String, SnapshotObject> objects = new HashMap<>();
    try {
        final XMLInputFactory factory = XMLInputFactory.newInstance();
        final XMLEventReader eventReader = factory.createXMLEventReader(inputStream);
        String sessionId = null;
        BigInteger serial = null;
        String uri = null;
        StringBuilder base64 = new StringBuilder();
        boolean inPublishElement = false;
        final Base64.Decoder decoder = Base64.getDecoder();
        while (eventReader.hasNext()) {
            final XMLEvent event = eventReader.nextEvent();
            switch(event.getEventType()) {
                case XMLStreamConstants.START_ELEMENT:
                    final StartElement startElement = event.asStartElement();
                    final String qName = startElement.getName().getLocalPart().toLowerCase(Locale.ROOT);
                    switch(qName) {
                        case "publish":
                            uri = getAttr(startElement, "uri", "Uri is not present in 'publish' element");
                            inPublishElement = true;
                            break;
                        case "snapshot":
                            serial = new BigInteger(getAttr(startElement, "serial", "Notification serial is not present"));
                            sessionId = getAttr(startElement, "session_id", "Session id is not present");
                            break;
                    }
                    break;
                case XMLStreamConstants.CHARACTERS:
                    final Characters characters = event.asCharacters();
                    if (inPublishElement) {
                        final String thisBase64 = characters.getData();
                        base64.append(thisBase64.replaceAll("\\s", ""));
                    }
                    break;
                case XMLStreamConstants.END_ELEMENT:
                    final EndElement endElement = event.asEndElement();
                    final String qqName = endElement.getName().getLocalPart().toLowerCase(Locale.ROOT);
                    if ("publish".equals(qqName)) {
                        final byte[] decoded = decoder.decode(base64.toString());
                        objects.put(uri, new SnapshotObject(decoded, uri));
                        inPublishElement = false;
                        base64 = new StringBuilder();
                    }
                    break;
            }
        }
        return new Snapshot(objects, sessionId, serial);
    } catch (XMLStreamException e) {
        throw new RrdpException("Couldn't parse snapshot: ", e);
    }
}
Also used : Base64(java.util.Base64) HashMap(java.util.HashMap) EndElement(javax.xml.stream.events.EndElement) Characters(javax.xml.stream.events.Characters) StartElement(javax.xml.stream.events.StartElement) XMLStreamException(javax.xml.stream.XMLStreamException) XMLEvent(javax.xml.stream.events.XMLEvent) XMLEventReader(javax.xml.stream.XMLEventReader) BigInteger(java.math.BigInteger) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 27 with Decoder

use of java.util.Base64.Decoder in project openmrs-core by openmrs.

the class SecurityTest method decrypt_shouldDecryptShortAndLongText.

/**
 * @see Security#decrypt(String)
 */
@Test
public void decrypt_shouldDecryptShortAndLongText() {
    final Decoder base64 = Base64.getDecoder();
    // use specific IV and Key
    byte[] initVector = base64.decode("9wyBUNglFCRVSUhMfsTa3Q==");
    byte[] secretKey = base64.decode("dTfyELRrAICGDwzjHDjuhw==");
    // perform decryption
    String expected = "this is fantasmic";
    String encrypted = "GnMz8qETyKMv+edLpYqWfBhR+lX6JlkocNGwHhmhXSY=";
    String actual = Security.decrypt(encrypted, initVector, secretKey);
    Assert.assertTrue(OpenmrsUtil.nullSafeEquals(expected, actual));
    expected = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus porta sapien ac nisi imperdiet posuere. Ma" + "ecenas nec felis ac enim posuere semper. In arcu turpis, elementum nec auctor id, pretium sed tortor. Quisque " + "sit amet erat ante. Praesent metus dui, porttitor non volutpat eu, porta sed ante. Fusce quis dignissim nisl. " + "Vivamus id massa in nisl sollicitudin iaculis ac ut odio. Morbi et sapien non massa ultricies commodo. Nunc se" + "mper, nulla a pellentesque adipiscing, urna nisl vulputate lacus, non rutrum nulla mauris at tortor. Quisque m" + "olestie, velit nec vehicula tempor, mi eros fermentum ipsum, ut ullamcorper nisl sem at risus. Nam varius nunc" + " sit amet velit blandit gravida sed vel purus. Nam ac justo ut metus elementum vehicula ac non ante. Aliquam p" + "ellentesque semper mauris ut pulvinar.Duis et orci nisi. Mauris tempor consequat felis, vel consequat diam con" + "sequat vitae. Donec eget dolor quis nulla lobortis vestibulum. Quisque vel ipsum in sapien egestas blandit. Pr" + "aesent malesuada tellus nec sapien blandit sit amet molestie magna consequat. Pellentesque quis tempus urna. Q" + "uisque ut nibh ut tellus hendrerit rhoncus. Aenean ultricies lorem eu sem condimentum at consectetur magna dig" + "nissim. Nam porta lobortis consequat. Suspendisse congue, tellus quis sodales blandit, augue massa interdum se" + "m, vel suscipit ipsum risus vitae massa. Quisque ipsum tellus, gravida sed suscipit non, ultricies eu augue. E" + "tiam consequat consequat massa a accumsan. Quisque rhoncus nisi lectus, vel ultrices sapien. Aenean a felis fe" + "lis, sit amet vestibulum lorem. Cras ut fermentum magna.Quisque vel erat eget eros bibendum convallis vitae a " + "augue. Maecenas posuere ullamcorper quam, ac ullamcorper eros egestas at. Nulla ipsum purus, venenatis ac dign" + "issim in, bibendum eget enim. Nulla rhoncus dui eu augue egestas in tempus augue congue. Suspendisse potenti. " + "Aenean faucibus felis ut leo venenatis congue lacinia felis tempor. Phasellus fermentum nisl venenatis quam mo" + "lestie fermentum euismod metus pretium. Duis facilisis pharetra vehicula. Class aptent taciti sociosqu ad lito" + "ra torquent per conubia nostra, per inceptos himenaeos. Donec aliquet feugiat sapien, vitae tristique nisl lac" + "inia non. Fusce eros dolor, egestas et auctor vel, aliquam ac lorem. In lacinia cursus pretium.Nulla vitae nis" + "i vitae magna varius posuere. Curabitur non dui at odio scelerisque mattis a a risus. Suspendisse augue lacus," + " pulvinar vitae fringilla tempor, adipiscing vel velit. Suspendisse lorem dui, eleifend vel rhoncus ac, porta " + "sed odio. Maecenas eget pellentesque ligula. Cras vitae auctor justo. Duis at massa vitae risus semper element" + "um. Proin at magna et augue volutpat tincidunt nec sed erat. Quisque id sapien tortor, ut gravida erat. Vivamu" + "s dictum, enim non sodales laoreet, ante libero suscipit erat, ac tristique purus eros sed augue. Quisque magn" + "a mi, varius ac accumsan aliquam, aliquam id risus. Phasellus dignissim dictum massa, ac consequat risus venen" + "atis in. Morbi imperdiet bibendum sem, eu mollis urna aliquet a. In ac augue vitae ante ultrices sollicitudin " + "vel sed elit. Nunc fringilla vestibulum egestas. Duis risus lorem, varius a vulputate at, blandit vel lectus. " + "Sed mollis, ipsum nec fringilla accumsan, risus nibh iaculis ligula, non tristique nibh tortor vitae sem. Null" + "a facilisi. In id lectus vitae felis elementum lobortis. Aenean et nisi orci.Nam mi lorem, posuere non auctor " + "sed, accumsan eu magna. Fusce sit amet tellus augue. Nunc eleifend, justo id pharetra hendrerit, urna augue ul" + "tricies mi, sed fringilla arcu libero quis nulla. Maecenas tristique auctor cursus. Curabitur venenatis lacus " + "non leo aliquet ornare. Praesent justo turpis, dictum eu dictum convallis, faucibus sit amet erat. Praesent se" + "d dui id enim euismod interdum. Integer sed fermentum neque. Curabitur enim nunc, euismod adipiscing iaculis e" + "get, tincidunt vel nunc. Nullam at neque sem, rutrum aliquet elit. In et velit enim, tempus mollis nunc. Sed s" + "it amet quam justo. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur convallis dolor non lig" + "ula fermentum imperdiet.";
    encrypted = "owV/Mh80CUvbu7zfmKqQVl7OdHlhokcyjRdCvIWPdnTQbakQVwYhOpkJ4cFzo1FF7kK8ErB+VaN76W6lJtR7eQw3Ugfm4jGHagA+zn7un/" + "4DkfjI5GxaJj904Gtdv0kV0aluJLBa8Mx8uPNWPL/BkWUru8E/kwysr9BzzPr6PhFOM7G2c+N8hwaYBZEyu021vLrt+6yHbI56HEUuVh2ssGm8O" + "0xQFHS3lvTT0oBFQKCdUi+sULrTYc9GzARuyS8Rp0BENHGUKVCU5zqKuW/PMk5BHZLd0aGh2VvvtDoxZ6fwqQozPeGyOeOfUFs46dQIDNy+wwIW" + "klPE/H+egu9woGZS+BYKDTiHlYjp4jkRTJTZ0jeNOCNfnPbbTYIz1V2Y7z9MPWWzeEZIRtNOTUO1ocSWTCNH5XPCnwO07V7VgaGHeLZhSJSu37w" + "yiXNJlroWkDEA9Fuug9sS4FfDTdfEzWu3BYMPIvcJQcxU0Q2TxkbqpjQbZHIkT/ffTAZYPfPZWTjezQe9mqrgdlcq1FZyt5/F7GDg+KklQTmqAj" + "qt9WEcCFqAX4HHj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s6SOuKAD1Jr6thSyN+hBerbYPAxSytS" + "Tw2SOAxzHVacOaPBdnSqWvnh5mRjmqK078uNNII0koTZSNxBgwDe15ntajZ1wTRMHdntbCVUoGhdM4xYj24Yb1uWUJsd9vcUZzrP7LhvVW/ybFO" + "jiO/YFlp3FkxfjND02mavm5h3W+d65Ch7LlCe2CQFJCMLVXUtFHhGVumZitZFbKPzrMwCUzHa5p5fdbYo02giUptTi365zNeI8vMJe2jejYSNrL" + "i3DuXY31xmMokxofyIgYjArsgKRodbEpP45qd5X5qt8OaMq4ZhutlG2tciU48usHTx4/rHzj2iP0njmznPWgx1aWE2g31pCA7RTtip6Lubg3Z8t" + "8BppmmrP+s7jThZPvUeUSf+NloN9Cu/8sd4CV/cE6QUY0JE+ZoSjtYScAKHfQHzDwdb+eUuYrJ7Y6JCwzw/l9FEGh0po4jIfiyzfOmmBgSSDYRm" + "EpIZ0sMQy57/L+utOT4AU5T3n/QiP3QsITdlVCqqY0UMt0+wQhJF++nrliBfQNFm+bQGych3oG4+vxDjoiQ3WJ1OXkmqT92RTELzx/pWRZhvx6a" + "QR0VMzAdJKrsE5TgNsfYy6AACBiUnujhN+4KRQiFWxrgAfs02Q8eySiPXLghDElym8HgiM2CZdV66UOifHAYtLPZUc3imANE4B31Fvs4VSHtJne" + "t9mHrJ+FI181rG5bdf62ZsSuziuQ==";
    actual = Security.decrypt(encrypted, initVector, secretKey);
    Assert.assertTrue(OpenmrsUtil.nullSafeEquals(expected, actual));
}
Also used : Decoder(java.util.Base64.Decoder) Test(org.junit.Test)

Example 28 with Decoder

use of java.util.Base64.Decoder in project j2objc by google.

the class Base64Test method testDecoder_extraChars_url.

/**
 * Checks decoding of bytes containing a value outside of the allowed
 * {@link #TABLE_2 url alphabet}.
 */
public void testDecoder_extraChars_url() throws Exception {
    // uses Table 2
    Decoder urlDecoder = Base64.getUrlDecoder();
    // Check failure cases common to both RFC4648 table 1 and table 2 decoding.
    checkDecoder_extraChars_common(urlDecoder);
    // Tests characters that are part of RFC4848 Table 1 but not Table 2.
    assertDecodeThrowsIAe(urlDecoder, "/aGVsbG8sIHdvcmx");
    assertDecodeThrowsIAe(urlDecoder, "aGV/sbG8sIHdvcmx");
    assertDecodeThrowsIAe(urlDecoder, "aGVsbG8sIHdvcmx/");
}
Also used : Decoder(java.util.Base64.Decoder)

Example 29 with Decoder

use of java.util.Base64.Decoder in project j2objc by google.

the class Base64Test method testEncoder_lineLength.

public void testEncoder_lineLength() throws Exception {
    String in_56 = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd";
    String in_57 = in_56 + "e";
    String in_58 = in_56 + "ef";
    String in_59 = in_56 + "efg";
    String in_60 = in_56 + "efgh";
    String in_61 = in_56 + "efghi";
    String prefix = "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5emFi";
    String out_56 = prefix + "Y2Q=";
    String out_57 = prefix + "Y2Rl";
    String out_58 = prefix + "Y2Rl\r\nZg==";
    String out_59 = prefix + "Y2Rl\r\nZmc=";
    String out_60 = prefix + "Y2Rl\r\nZmdo";
    String out_61 = prefix + "Y2Rl\r\nZmdoaQ==";
    Encoder encoder = Base64.getMimeEncoder();
    Decoder decoder = Base64.getMimeDecoder();
    assertEquals("", encodeFromAscii(encoder, decoder, ""));
    assertEquals(out_56, encodeFromAscii(encoder, decoder, in_56));
    assertEquals(out_57, encodeFromAscii(encoder, decoder, in_57));
    assertEquals(out_58, encodeFromAscii(encoder, decoder, in_58));
    assertEquals(out_59, encodeFromAscii(encoder, decoder, in_59));
    assertEquals(out_60, encodeFromAscii(encoder, decoder, in_60));
    assertEquals(out_61, encodeFromAscii(encoder, decoder, in_61));
    encoder = Base64.getUrlEncoder();
    decoder = Base64.getUrlDecoder();
    assertEquals(out_56.replaceAll("\r\n", ""), encodeFromAscii(encoder, decoder, in_56));
    assertEquals(out_57.replaceAll("\r\n", ""), encodeFromAscii(encoder, decoder, in_57));
    assertEquals(out_58.replaceAll("\r\n", ""), encodeFromAscii(encoder, decoder, in_58));
    assertEquals(out_59.replaceAll("\r\n", ""), encodeFromAscii(encoder, decoder, in_59));
    assertEquals(out_60.replaceAll("\r\n", ""), encodeFromAscii(encoder, decoder, in_60));
    assertEquals(out_61.replaceAll("\r\n", ""), encodeFromAscii(encoder, decoder, in_61));
}
Also used : Encoder(java.util.Base64.Encoder) Decoder(java.util.Base64.Decoder)

Example 30 with Decoder

use of java.util.Base64.Decoder in project j2objc by google.

the class Base64Test method testDecoder_extraChars_basic.

/**
 * Checks decoding of bytes containing a value outside of the allowed
 * {@link #TABLE_1 "basic" alphabet}.
 */
public void testDecoder_extraChars_basic() throws Exception {
    // uses Table 1
    Decoder basicDecoder = Base64.getDecoder();
    // Check failure cases common to both RFC4648 Table 1 and Table 2 decoding.
    checkDecoder_extraChars_common(basicDecoder);
    // Tests characters that are part of RFC4848 Table 2 but not Table 1.
    assertDecodeThrowsIAe(basicDecoder, "_aGVsbG8sIHdvcmx");
    assertDecodeThrowsIAe(basicDecoder, "aGV_sbG8sIHdvcmx");
    assertDecodeThrowsIAe(basicDecoder, "aGVsbG8sIHdvcmx_");
}
Also used : Decoder(java.util.Base64.Decoder)

Aggregations

Decoder (java.util.Base64.Decoder)27 Base64 (java.util.Base64)21 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)7 Encoder (java.util.Base64.Encoder)7 KeyFactory (java.security.KeyFactory)6 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)6 IOException (java.io.IOException)5 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)5 JOSEObjectType (com.nimbusds.jose.JOSEObjectType)4 JWSAlgorithm (com.nimbusds.jose.JWSAlgorithm)4 JWSHeader (com.nimbusds.jose.JWSHeader)4 JWSSigner (com.nimbusds.jose.JWSSigner)4 MACSigner (com.nimbusds.jose.crypto.MACSigner)4 JWKSource (com.nimbusds.jose.jwk.source.JWKSource)4 DefaultJOSEObjectTypeVerifier (com.nimbusds.jose.proc.DefaultJOSEObjectTypeVerifier)4 JWSKeySelector (com.nimbusds.jose.proc.JWSKeySelector)4 JWSVerificationKeySelector (com.nimbusds.jose.proc.JWSVerificationKeySelector)4 JWTClaimsSet (com.nimbusds.jwt.JWTClaimsSet)4 SignedJWT (com.nimbusds.jwt.SignedJWT)4 RSAPublicKey (java.security.interfaces.RSAPublicKey)4