当前位置: 首页>>代码示例>>Java>>正文


Java Base64.encodeToString方法代码示例

本文整理汇总了Java中android.util.Base64.encodeToString方法的典型用法代码示例。如果您正苦于以下问题:Java Base64.encodeToString方法的具体用法?Java Base64.encodeToString怎么用?Java Base64.encodeToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.util.Base64的用法示例。


在下文中一共展示了Base64.encodeToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkSignature

import android.util.Base64; //导入方法依赖的package包/类
public static boolean checkSignature(Context context) {
    try {
        PackageInfo packageInfo = context.getPackageManager()
                .getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES);
        for (Signature signature : packageInfo.signatures) {
            MessageDigest sha = MessageDigest.getInstance("SHA");
            sha.update(signature.toByteArray());
            final String currentSignature = Base64.encodeToString(sha.digest(), Base64.DEFAULT);
            if (SIGNATURE.equals(currentSignature)) {
                return true;
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "Failed to check signature", e);
    }

    return false;
}
 
开发者ID:rafaeltoledo,项目名称:android-security,代码行数:19,代码来源:SignatureUtils.java

示例2: encrypt

import android.util.Base64; //导入方法依赖的package包/类
static String encrypt(String plaintext, String key, EncodingType encodingType) throws UnsupportedEncodingException {
	// Set up cipher algo
	RNCryptorNative c = new RNCryptorNative();
	
	// Encode the plaintext
	byte[] plaintextBytes = Base64.encode(plaintext.getBytes("utf-8"), Base64.DEFAULT);

	// Encrypt
	byte[] ciphertextBytes = c.encrypt(new String(plaintextBytes), formatKey(key));

	String ret;
	switch (encodingType) {
       case HEX:
       	ret = EncodingHelper.bytesToHex(ciphertextBytes);
       	ret = ret.toLowerCase();
       	break;
       case BASE64:
       	ret = Base64.encodeToString(ciphertextBytes, Base64.DEFAULT);
       	break;
       default: // Base64 by default
       	ret = Base64.encodeToString(ciphertextBytes, Base64.DEFAULT);
       }
	
	return ret;
}
 
开发者ID:LDLN,项目名称:Responder-Android,代码行数:26,代码来源:EncryptionHelper.java

示例3: getRetrofit

import android.util.Base64; //导入方法依赖的package包/类
public static RetrofitInterface getRetrofit(String email, String password) {

        String credentials = email + ":" + password;
        String basic = "Basic " + Base64.encodeToString(credentials.getBytes(),Base64.NO_WRAP);
        OkHttpClient.Builder httpClient = new OkHttpClient.Builder();

        httpClient.addInterceptor(chain -> {

            Request original = chain.request();
            Request.Builder builder = original.newBuilder()
                    .addHeader("Authorization", basic)
                    .method(original.method(),original.body());
            return  chain.proceed(builder.build());

        });

        RxJavaCallAdapterFactory rxAdapter = RxJavaCallAdapterFactory.createWithScheduler(Schedulers.io());

        return new Retrofit.Builder()
                .baseUrl(Constants.BASE_URL)
                .client(httpClient.build())
                .addCallAdapterFactory(rxAdapter)
                .addConverterFactory(GsonConverterFactory.create())
                .build().create(RetrofitInterface.class);
    }
 
开发者ID:EdwardAlexis,项目名称:Sistema-de-Comercializacion-Negocios-Jhordan,代码行数:26,代码来源:NetworkUtil.java

示例4: sendData

import android.util.Base64; //导入方法依赖的package包/类
private String sendData() {
    String requestURL =  getString(R.string.feedback_url);
    HashMap<String, String> postDataParams = new HashMap<>();

    String comment = ((EditText)findViewById(R.id.err_user_comment)).getText().toString();
    if (comment.length()>0) {
        comment = "\ncomment:" +  Base64.encodeToString(comment.getBytes(),Base64.DEFAULT) + "\n";
    }
    postDataParams.put("app",appname);
    postDataParams.put("data", error + comment);

    String response = HttpUtils.sendPostData(requestURL, postDataParams);

    Log.d("err-report" , response);

    return response;
}
 
开发者ID:quaap,项目名称:LaunchTime,代码行数:18,代码来源:CrashReportActivity.java

示例5: encrypt

import android.util.Base64; //导入方法依赖的package包/类
/**
 * Encrypt and encode message using 256-bit AES with key generated from password.
 *
 *
 * @param password used to generated key
 * @param message the thing you want to encrypt assumed String UTF-8
 * @return Base64 encoded CipherText
 * @throws GeneralSecurityException if problems occur during encryption
 */
public static String encrypt(final String password, String message)
        throws GeneralSecurityException {

    try {
        final SecretKeySpec key = generateKey(password);

        log("message", message);

        byte[] cipherText = encrypt(key, ivBytes, message.getBytes(CHARSET));

        //NO_WRAP is important as was getting \n at the end
        String encoded = Base64.encodeToString(cipherText, Base64.NO_WRAP);
        log("Base64.NO_WRAP", encoded);
        return encoded;
    } catch (UnsupportedEncodingException e) {
        if (DEBUG_LOG_ENABLED)
            Log.e(TAG, "UnsupportedEncodingException ", e);
        throw new GeneralSecurityException(e);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:30,代码来源:AESCrypt.java

示例6: getBase64FromFile

import android.util.Base64; //导入方法依赖的package包/类
/**
 * 将图片文件转化为字节数组字符串,并对其进行Base64编码处理
 *
 * @param header   头部信息
 * @param filePath 本地路径
 * @return Base64编码
 */
public static String getBase64FromFile(String header, String filePath) {
    if (filePath == null || filePath.length() == 0) {
        return "File path does not exist!";
    }

    byte[] data = null;
    try {
        InputStream in = new FileInputStream(filePath);
        data = new byte[in.available()];
        in.read(data);
        in.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // 对字节数组Base64编码
    return header != null ? header + Base64.encodeToString(data, Base64.DEFAULT) : Base64.encodeToString(data, Base64.DEFAULT);
}
 
开发者ID:RockyQu,项目名称:MVVMFrames,代码行数:26,代码来源:FileUtils.java

示例7: getSignedData

import android.util.Base64; //导入方法依赖的package包/类
public String getSignedData(String b64data) {
    PrivateKey privkey = getKeystoreKey();
    byte[] data = Base64.decode(b64data, Base64.DEFAULT);
    // The Jelly Bean *evil* Hack
    // 4.2 implements the RSA/ECB/PKCS1PADDING in the OpenSSLprovider
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN) {
        return processSignJellyBeans(privkey, data);
    }
    try {
        /* ECB is perfectly fine in this special case, since we are using it for
           the public/private part in the TLS exchange
         */
        @SuppressLint("GetInstance") Cipher rsaSigner = Cipher.getInstance("RSA/ECB/PKCS1PADDING");
        rsaSigner.init(Cipher.ENCRYPT_MODE, privkey);
        byte[] signed_bytes = rsaSigner.doFinal(data);
        return Base64.encodeToString(signed_bytes, Base64.NO_WRAP);
    } catch (NoSuchAlgorithmException | InvalidKeyException | IllegalBlockSizeException
            | BadPaddingException | NoSuchPaddingException e) {
        VpnStatus.logError(R.string.error_rsa_sign, e.getClass().toString(), e.getLocalizedMessage());
        return null;
    }
}
 
开发者ID:akashdeepsingh9988,项目名称:Cybernet-VPN,代码行数:23,代码来源:VpnProfile.java

示例8: imageToBase64

import android.util.Base64; //导入方法依赖的package包/类
/**
 * Convert an image to base64
 * @param image the image to convert
 * @return the image as a base64 string
 */
public static String imageToBase64(Bitmap image){
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    // put image into the output stream
    image.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
    return Base64.encodeToString(outputStream.toByteArray(), Base64.DEFAULT);
}
 
开发者ID:CMPUT301F17T09,项目名称:GoalsAndHabits,代码行数:12,代码来源:ImageController.java

示例9: getEncodedBitmap

import android.util.Base64; //导入方法依赖的package包/类
public String getEncodedBitmap() {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    try {
        pic.compress(Bitmap.CompressFormat.JPEG, 40, stream);
    }
    catch (NullPointerException npe) {}
    byte[] byteFormat = stream.toByteArray();
    // get the base 64 string
    String imgString = Base64.encodeToString(byteFormat, Base64.NO_WRAP);
    return imgString;
}
 
开发者ID:umdcs,项目名称:linkedout_procon,代码行数:12,代码来源:ProfilePic.java

示例10: getClient

import android.util.Base64; //导入方法依赖的package包/类
static <T> T getClient(Class<T> cls, String username, String psw, String url) {

        OkHttpClient.Builder builder = new OkHttpClient().newBuilder();
        builder.readTimeout(10, TimeUnit.SECONDS);
        builder.connectTimeout(5, TimeUnit.SECONDS);

        if(BuildConfig.DEBUG){
            builder.addInterceptor(new LoggingInterceptor());
        }

        String credentials = username + ":" + psw;
        final String basic =
                "Basic " + Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);

        builder.addInterceptor(new Interceptor() {
            @Override public Response intercept(Chain chain) throws IOException {
                Request request = chain.request().newBuilder()
                        .addHeader("Authorization", basic)
                        .addHeader("Accept", "application/json")
                        .build();
                return chain.proceed(request);
            }
        });

        OkHttpClient client = builder.build();

        Gson gson = new GsonBuilder()
                .setDateFormat("yyyy-MM-dd HH:mm:ss")
                .create();

        Retrofit retrofit =
                new Retrofit.Builder()
                        .baseUrl(url+API_URL)
                        .client(client)
                        .addConverterFactory(GsonConverterFactory.create(gson))
                        .build();

        return retrofit.create(cls);
    }
 
开发者ID:alextselegidis,项目名称:easyappointments-android-client,代码行数:40,代码来源:BaseServiceFactory.java

示例11: putImage

import android.util.Base64; //导入方法依赖的package包/类
/**
 * 保存图片到SharedPreferences
 *
 * @param mContext
 * @param imageView
 */
public static void putImage(Context mContext, String key, ImageView imageView) {
    BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
    Bitmap bitmap = drawable.getBitmap();
    // 将Bitmap压缩成字节数组输出流
    ByteArrayOutputStream byStream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 80, byStream);
    // 利用Base64将我们的字节数组输出流转换成String
    byte[] byteArray = byStream.toByteArray();
    String imgString = new String(Base64.encodeToString(byteArray, Base64.DEFAULT));
    // 将String保存shareUtils
    SPUtils.put(mContext, key, imgString);
}
 
开发者ID:Loofer,项目名称:Watermark,代码行数:19,代码来源:SPUtils.java

示例12: generateKeyString

import android.util.Base64; //导入方法依赖的package包/类
/**
 * 生成一个AES密钥字符串
 *
 * @return
 */
public static String generateKeyString() {
    try {
        KeyGenerator kgen = KeyGenerator.getInstance("AES");
        kgen.init(128, new SecureRandom());
        SecretKey secretKey = kgen.generateKey();
        byte[] enCodeFormat = secretKey.getEncoded();
        SecretKeySpec secretKeySpec = new SecretKeySpec(enCodeFormat, "AES");
        return Base64.encodeToString(secretKeySpec.getEncoded(), Base64.DEFAULT);
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:huashengzzz,项目名称:SmartChart,代码行数:19,代码来源:AES.java

示例13: getBitmapStrBase64

import android.util.Base64; //导入方法依赖的package包/类
@SuppressLint("NewApi")
public static String getBitmapStrBase64(Bitmap bitmap) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(CompressFormat.PNG, 100, baos);
    byte[] bytes = baos.toByteArray();
    String data = Base64.encodeToString(bytes, 0, bytes.length,
                                        Base64.DEFAULT);

    if (bitmap != null) {
        bitmap.recycle();
        bitmap = null;
    }

    return data;
}
 
开发者ID:zqHero,项目名称:rongyunDemo,代码行数:16,代码来源:BitmapUtils.java

示例14: privateBase64Encoder

import android.util.Base64; //导入方法依赖的package包/类
/**
 * private Encoder in base64
 *
 * @param toEncode String to be encoded
 * @param flags flags to encode the String
 * @return encoded String in base64
 */
private static String privateBase64Encoder(String toEncode, int flags) {
    byte[] data = null;
    try {
        data = toEncode.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e1) {
        e1.printStackTrace();
    }

    if (flags == -1) {
        flags = Base64.DEFAULT;
    }

    return Base64.encodeToString(data, flags);
}
 
开发者ID:yongbeam,项目名称:AirQuickUtils,代码行数:22,代码来源:AirSecurity.java

示例15: bitmaptoString

import android.util.Base64; //导入方法依赖的package包/类
/**
 * 将Bitmap转换成字符串
 *
 * @param bitmap
 * @return
 */
public static String bitmaptoString(Bitmap bitmap) {
    String string = null;
    ByteArrayOutputStream bStream = new ByteArrayOutputStream();
    bitmap.compress(CompressFormat.PNG, 100, bStream);
    byte[] bytes = bStream.toByteArray();
    string = Base64.encodeToString(bytes, Base64.DEFAULT);
    return string;
}
 
开发者ID:f-evil,项目名称:EVideoRecorder,代码行数:15,代码来源:ImageUtils.java


注:本文中的android.util.Base64.encodeToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。