本文整理汇总了Java中android.util.Base64.decode方法的典型用法代码示例。如果您正苦于以下问题:Java Base64.decode方法的具体用法?Java Base64.decode怎么用?Java Base64.decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.util.Base64
的用法示例。
在下文中一共展示了Base64.decode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decrypt
import android.util.Base64; //导入方法依赖的package包/类
public static String decrypt(String encrypted, String key) {
try {
byte[] decoded = Base64.decode(encrypted, Base64.DEFAULT);
Cipher c = Cipher.getInstance("AES/ECB/PKCS5Padding");
SecretKeySpec keySpec = new SecretKeySpec(key.getBytes("ASCII"), "AES");
c.init(Cipher.DECRYPT_MODE, keySpec);
byte[] decrypted = c.doFinal(decoded);
return new String(decrypted);
} catch (Exception e) {
Log.e(LOG_TAG, "Pack decryption failed. Error: " + e.getMessage());
}
return "";
}
示例2: decode
import android.util.Base64; //导入方法依赖的package包/类
public static Server decode(String data)
{
final String[] split = data.split(";");
final String name = new String(Base64.decode(split[0], Base64.DEFAULT));
final String uuid = split[1];
return new Server(name, uuid);
}
示例3: readDataUri
import android.util.Base64; //导入方法依赖的package包/类
private OpenForReadResult readDataUri(Uri uri) {
String uriAsString = uri.getSchemeSpecificPart();
int commaPos = uriAsString.indexOf(',');
if (commaPos == -1) {
return null;
}
String[] mimeParts = uriAsString.substring(0, commaPos).split(";");
String contentType = null;
boolean base64 = false;
if (mimeParts.length > 0) {
contentType = mimeParts[0];
}
for (int i = 1; i < mimeParts.length; ++i) {
if ("base64".equalsIgnoreCase(mimeParts[i])) {
base64 = true;
}
}
String dataPartAsString = uriAsString.substring(commaPos + 1);
byte[] data;
if (base64) {
data = Base64.decode(dataPartAsString, Base64.DEFAULT);
} else {
try {
data = dataPartAsString.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
data = dataPartAsString.getBytes();
}
}
InputStream inputStream = new ByteArrayInputStream(data);
return new OpenForReadResult(uri, inputStream, contentType, data.length, null);
}
示例4: getCertificate
import android.util.Base64; //导入方法依赖的package包/类
private static X509Certificate getCertificate(Context c){
SharedPreferences deviceKeyPref = c.getSharedPreferences(c.getString(R.string.device_key_and_cert), MODE_PRIVATE);
try {
byte[] certificateBytes = Base64.decode(deviceKeyPref.getString(c.getString(R.string.certificate), ""), Base64.DEFAULT);
X509CertificateHolder certificateHolder = new X509CertificateHolder(certificateBytes);
return new JcaX509CertificateConverter().setProvider("BC").getCertificate(certificateHolder);
} catch (Exception e) {
Log.e("TlsHelper", "getCertificate");
Log.e("StackTrace", Log.getStackTraceString(e));
return null;
}
}
示例5: getImage
import android.util.Base64; //导入方法依赖的package包/类
/**
* 从SharedPreferences读取图片
*
* @param mContext
* @param imageView
*/
public static Bitmap getImage(Context mContext, String key, ImageView imageView) {
String imgString = (String) SPUtils.get(mContext, key, "");
if (!imgString.equals("")) {
// 利用Base64将我们string转换
byte[] byteArray = Base64.decode(imgString, Base64.DEFAULT);
ByteArrayInputStream byStream = new ByteArrayInputStream(byteArray);
// 生成bitmap
return BitmapFactory.decodeStream(byStream);
}
return null;
}
示例6: getDeviceData
import android.util.Base64; //导入方法依赖的package包/类
/**
* 将对象从shareprerence中取出来
*
* @param key
* @param <T>
* @return
*/
public static <T> T getDeviceData(Context context, String key) {
if (mSharedPreferences == null) {
mSharedPreferences = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
}
T device = null;
String productBase64 = mSharedPreferences.getString(key, null);
if (productBase64 == null) {
return null;
}
// 读取字节
byte[] base64 = Base64.decode(productBase64.getBytes(), Base64.DEFAULT);
// 封装到字节流
ByteArrayInputStream bais = new ByteArrayInputStream(base64);
try {
// 再次封装
ObjectInputStream bis = new ObjectInputStream(bais);
// 读取对象
device = (T) bis.readObject();
} catch (Exception e) {
e.printStackTrace();
}
return device;
}
示例7: getDeviceData
import android.util.Base64; //导入方法依赖的package包/类
/**
* 将对象从shareprerence中取出来
*
* @param key
* @param <T>
* @return
*/
public static <T> T getDeviceData(Context context, String key) {
if (mSharedPreferences == null) {
mSharedPreferences = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
}
T device = null;
String productBase64 = mSharedPreferences.getString(key, null);
if (productBase64 == null) {
return null;
}
// 读取字节
byte[] base64 = Base64.decode(productBase64.getBytes(), Base64.DEFAULT);
// 封装到字节流
ByteArrayInputStream bais = new ByteArrayInputStream(base64);
try {
// 再次封装
ObjectInputStream bis = new ObjectInputStream(bais);
// 读取对象
device = (T) bis.readObject();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return device;
}
示例8: decodeImage
import android.util.Base64; //导入方法依赖的package包/类
public static Bitmap decodeImage(String imageString) {
try {
byte[] encodeByte = Base64.decode(imageString, Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
return bitmap;
} catch (Exception e) {
e.getMessage();
return null;
}
}
示例9: isExtendedWebpSupported
import android.util.Base64; //导入方法依赖的package包/类
/**
* Checks whether underlying platform supports extended WebPs
*/
private static boolean isExtendedWebpSupported() {
// Lossless and extended formats are supported on Android 4.2.1+
// Unfortunately SDK_INT is not enough to distinguish 4.2 and 4.2.1
// (both are API level 17 (JELLY_BEAN_MR1))
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
return false;
}
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1) {
// Let's test if extended webp is supported
// To this end we will try to decode bounds of vp8x webp with alpha channel
byte[] decodedBytes = Base64.decode(VP8X_WEBP_BASE64, Base64.DEFAULT);
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(decodedBytes, 0, decodedBytes.length, opts);
// If Android managed to find appropriate decoder then opts.outHeight and opts.outWidth
// should be set. We can not assume that outMimeType is set.
// Android guys forgot to update logic for mime types when they introduced support for webp.
// For example, on 4.2.2 this field is not set for webp images.
if (opts.outHeight != 1 || opts.outWidth != 1) {
return false;
}
}
return true;
}
示例10: getPrivateKey
import android.util.Base64; //导入方法依赖的package包/类
static PrivateKey getPrivateKey(Context c){
try {
SharedPreferences deviceKeyPref = c.getSharedPreferences(c.getString(R.string.device_key_and_cert), MODE_PRIVATE);
byte[] privateKeyBytes = Base64.decode(deviceKeyPref.getString(c.getString(R.string.privatekey), ""), Base64.DEFAULT);
return KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(privateKeyBytes));
} catch (Exception e) {
Log.e("RsaHelper", "getPrivateKey");
Log.e("StackTrace", Log.getStackTraceString(e));
return null;
}
}
示例11: getArrayBuffer
import android.util.Base64; //导入方法依赖的package包/类
public byte[] getArrayBuffer(int index) throws JSONException {
String encoded = baseArgs.getString(index);
return Base64.decode(encoded, Base64.DEFAULT);
}
示例12: getBitmap
import android.util.Base64; //导入方法依赖的package包/类
Bitmap getBitmap() {
byte[] b = Base64.decode(encodedImage, Base64.DEFAULT);
return BitmapFactory.decodeByteArray(b, 0, b.length);
}
示例13: writeToFileAtURL
import android.util.Base64; //导入方法依赖的package包/类
@Override
public long writeToFileAtURL(LocalFilesystemURL inputURL, String data,
int offset, boolean isBinary) throws IOException, NoModificationAllowedException {
boolean append = false;
if (offset > 0) {
this.truncateFileAtURL(inputURL, offset);
append = true;
}
byte[] rawData;
if (isBinary) {
rawData = Base64.decode(data, Base64.DEFAULT);
} else {
rawData = data.getBytes(Charset.defaultCharset());
}
ByteArrayInputStream in = new ByteArrayInputStream(rawData);
try
{
byte buff[] = new byte[rawData.length];
String absolutePath = filesystemPathForURL(inputURL);
FileOutputStream out = new FileOutputStream(absolutePath, append);
try {
in.read(buff, 0, buff.length);
out.write(buff, 0, rawData.length);
out.flush();
} finally {
// Always close the output
out.close();
}
if (isPublicDirectory(absolutePath)) {
broadcastNewFile(Uri.fromFile(new File(absolutePath)));
}
}
catch (NullPointerException e)
{
// This is a bug in the Android implementation of the Java Stack
NoModificationAllowedException realException = new NoModificationAllowedException(inputURL.toString());
realException.initCause(e);
throw realException;
}
return rawData.length;
}
示例14: decrypt
import android.util.Base64; //导入方法依赖的package包/类
@Override
public byte[] decrypt(byte[] res) {
if(cipher != null) res = cipher.decrypt(res);
return Base64.decode(res, Base64.DEFAULT);
}
示例15: readFileAsString
import android.util.Base64; //导入方法依赖的package包/类
/**
* R.string.countries is a json string which is Base64 encoded to avoid
* special characters in XML. It's Base64 decoded here to get original json.
*
* @param context
* @return
* @throws java.io.IOException
*/
private static String readFileAsString(Context context)
throws java.io.IOException {
String base64 = context.getResources().getString(R.string.countries);
byte[] data = Base64.decode(base64, Base64.DEFAULT);
return new String(data, "UTF-8");
}