コード例 #1
0
  @Nullable
  @ReturnsMutableCopy
  public static byte[] getDecodedASCIIHex(@Nullable final byte[] aEncodedBuffer) {
    if (aEncodedBuffer == null) return null;

    final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream();
    try {
      boolean bFirstByte = true;
      int nFirstByte = 0;
      for (final byte nEncByte : aEncodedBuffer) {
        if (nEncByte == '>') break;

        // Ignore whitespaces
        if (Character.isWhitespace(nEncByte)) continue;

        final byte nDecByte = (byte) StringHelper.getHexValue((char) nEncByte);
        if (nDecByte == CGlobal.ILLEGAL_UINT)
          throw new DecodeException(
              "Failed to convert byte '"
                  + nEncByte
                  + "/"
                  + ((char) nEncByte)
                  + "' to hex value in ASCIIHexDecode");
        if (bFirstByte) nFirstByte = nDecByte;
        else aBAOS.write((byte) (nFirstByte << 4 | nDecByte));
        bFirstByte = !bFirstByte;
      }

      // Write trailing byte
      if (!bFirstByte) aBAOS.write((byte) (nFirstByte << 4));
      return aBAOS.toByteArray();
    } finally {
      StreamHelper.close(aBAOS);
    }
  }
コード例 #2
0
 public void save(@WillClose final OutputStream aOS, final char[] aPassword)
     throws OpenAS2Exception {
   try {
     final KeyStore aKeyStore = getKeyStore();
     synchronized (aKeyStore) {
       aKeyStore.store(aOS, aPassword);
     }
   } catch (final IOException ex) {
     throw WrappedOpenAS2Exception.wrap(ex);
   } catch (final GeneralSecurityException ex) {
     throw WrappedOpenAS2Exception.wrap(ex);
   } finally {
     StreamHelper.close(aOS);
   }
 }
コード例 #3
0
 public void load(@Nonnull @WillClose final InputStream aIS, @Nonnull final char[] aPassword)
     throws OpenAS2Exception {
   try {
     final KeyStore aKeyStore = getKeyStore();
     synchronized (aKeyStore) {
       aKeyStore.load(aIS, aPassword);
     }
   } catch (final IOException ex) {
     throw WrappedOpenAS2Exception.wrap(ex);
   } catch (final GeneralSecurityException ex) {
     throw WrappedOpenAS2Exception.wrap(ex);
   } finally {
     StreamHelper.close(aIS);
   }
 }