Package sun.misc

Examples of sun.misc.BASE64Decoder


  public void uploadBase64(String fieldName){
    String savePath = this.getFolder(this.savePath);
    String base64Data = this.request.getParameter(fieldName);
    this.fileName = this.getName("test.png");
    this.url = savePath + "/" + this.fileName;
    BASE64Decoder decoder = new BASE64Decoder();
    try {
      File outFile = new File(this.getPhysicalPath(this.url));
      OutputStream ro = new FileOutputStream(outFile);
      byte[] b = decoder.decodeBuffer(base64Data);
      for (int i = 0; i < b.length; ++i) {
        if (b[i] < 0) {
          b[i] += 256;
        }
      }
View Full Code Here


        return temp;
    }
    public static String getFromBASE64(String s) {
        if (s == null)
            return null;
        BASE64Decoder decoder = new BASE64Decoder();
        try {
            byte[] b = decoder.decodeBuffer(s);
            return new String(b);
        } catch (Exception e) {
            return null;
        }
    }
View Full Code Here

    public String decrypt(String text) throws GeneralSecurityException, IOException {
        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(CIPHER);
        SecretKey key = keyFactory.generateSecret(new PBEKeySpec(SECRET));
        Cipher pbeCipher = Cipher.getInstance(CIPHER);
        pbeCipher.init(Cipher.DECRYPT_MODE, key, new PBEParameterSpec(SALT, 20));
        return new String(pbeCipher.doFinal(new BASE64Decoder().decodeBuffer(text)));
    }
View Full Code Here

        String authorization = request.getHeader("authorization");
        //Get credentials from authourization header.
        if (authorization != null
                && authorization.toLowerCase().startsWith("basic ")) {
            authorization = authorization.substring(6).trim();
            BASE64Decoder decoder = new BASE64Decoder();
            byte[] bs = decoder.decodeBuffer(authorization);
            String decodedString = new String(bs);
            int ind = decodedString.indexOf(':');
            if (ind > 0) {
                username = decodedString.substring(0, ind);
                password = decodedString.substring(ind + 1);
View Full Code Here

  }

  public static String decrypt(String salt, String content) throws Exception {
    Cipher cipher = Cipher.getInstance(ALGORITHM);
    cipher.init(Cipher.DECRYPT_MODE, generateKey(salt));
    byte[] decryptedBytes = cipher.doFinal(new BASE64Decoder().decodeBuffer(content));
    return new String(decryptedBytes);
  }
View Full Code Here

    }
  }

  public void fromJSON( JSONObject json ) throws JSONException {
    try {
      BASE64Decoder base64Decoder = new BASE64Decoder();

      String _description, _name, _id, _key, _user, _solution, _path, _file;
      Date _timestamp;
      JSONObject jsonUserData, jsonParams;
      Map<String, Object> _params = new HashMap<String, Object>(), _userData = new HashMap<String, Object>();
      _description = json.optString( "description" );
      _name = json.getString( "name" );
      _id = json.getString( "id" );
      _timestamp = new Date( json.optLong( "timestamp", 0 ) );
      _user = json.getString( "user" );
      _key = json.isNull( "key" ) ? null : json.optString( "key" );
      _solution = json.getString( "solution" );
      _path = json.getString( "path" );
      _file = json.getString( "file" );
      String p = json.getString( "params" );
      try {
        jsonParams = new JSONObject( new String( base64Decoder.decodeBuffer( p ) ) );
      } catch ( IOException e ) {
        logger.error( e );
        throw new JSONException( e );
      }
      JSONArray jsonUnbound = json.getJSONArray( "unbound" );
      String[] keys = JSONObject.getNames( jsonParams );
      if ( keys != null ) {
        for ( String k : keys ) {
          _params.put( k, jsonParams.get( k ) );
        }
      }
      List<String> _unbound = new ArrayList<String>();
      for ( int i = 0; i < jsonUnbound.length(); i++ ) {
        _unbound.add( jsonUnbound.getString( i ) );
      }

      if ( json.has( "userData" ) ) {
        String u = json.getString( "userData" );
        try {
          jsonUserData = new JSONObject( new String( base64Decoder.decodeBuffer( u ) ) );
        } catch ( IOException e ) {
          logger.error( e );
          throw new JSONException( e );
        }
        String[] userDataKeys = JSONObject.getNames( jsonUserData );
View Full Code Here

        return new BASE64Encoder().encode( out.toByteArray() );
    }

    private static <T> T deserialize( Class<T> type, String buffer ) throws IOException, ClassNotFoundException
    {
        byte[] bytes = new BASE64Decoder().decodeBuffer( buffer );
        return type.cast( new ObjectInputStream( new ByteArrayInputStream( bytes ) ).readObject() );
    }
View Full Code Here

   */
  public String decrypt(String encryptedString) {
    String decryptedText = null;
    try {
      cipher.init(Cipher.DECRYPT_MODE, key);
      BASE64Decoder base64decoder = new BASE64Decoder();
      byte[] encryptedText = base64decoder.decodeBuffer(encryptedString);
      byte[] plainText = cipher.doFinal(encryptedText);
      decryptedText = bytes2String(plainText);
    } catch (Exception e) {
      e.printStackTrace();
    }
View Full Code Here

  private BASE64Encoder  encoder;

  public SunBase64Encoder() {
    super();
    this.decoder = new BASE64Decoder();
    this.encoder = new BASE64Encoder();
  }
View Full Code Here

  public void uploadBase64(String fieldName){
    String savePath = this.getFolder(this.savePath);
    String base64Data = this.request.getParameter(fieldName);
    this.fileName = this.getName("test.png");
    this.url = savePath + "/" + this.fileName;
    BASE64Decoder decoder = new BASE64Decoder();
    try {
      File outFile = new File(this.getPhysicalPath(this.url));
      OutputStream ro = new FileOutputStream(outFile);
      byte[] b = decoder.decodeBuffer(base64Data);
      for (int i = 0; i < b.length; ++i) {
        if (b[i] < 0) {
          b[i] += 256;
        }
      }
View Full Code Here

TOP

Related Classes of sun.misc.BASE64Decoder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.