導航:首頁 > 編程語言 > base64javac

base64javac

發布時間:2022-09-02 09:18:08

『壹』 C語言編程:編寫一個函數base64加密

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

constchar*chlist="+/";

intencode_string(char*str,unsignedintlength,char*stat){
chars[103];
inti,j;
unsignedtemp;
if(length<=0)return1;
if(length>100)return2;
str[length]='';
strcpy(s,str);
while(strlen(s)%3)strcat(s,"=");
for(i=0,j=0;s[i];i+=3,j+=4){
temp=s[i];
temp=(temp<<8)+s[i+1];
temp=(temp<<8)+s[i+2];
stat[j+3]=chlist[temp&0X3F];
temp>>=6;
stat[j+2]=chlist[temp&0X3F];
temp>>=6;
stat[j+1]=chlist[temp&0X3F];
temp>>=6;
stat[j+0]=chlist[temp&0X3F];
}
stat[j]='';
return0;
}

intIndex(charch){
inti;
for(i=0;chlist[i];++i){
if(chlist[i]==ch)
returni;
}
return-1;
}

voiddecode_string(char*s,char*t){
unsignedtemp;
inti,j,k,len=strlen(s);
if(len%4){
printf("無效數據。 ");
exit(2);
}
for(i=0,j=0;i<=len;i+=4,j+=3){
temp=0;
for(k=0;k<4;++k)
temp=(temp<<6)+Index(s[i+k]);
for(k=2;k>=0;--k){
t[j+k]=temp&0XFF;
temp>>=8;
}
}
t[j+k]='';
}

intmain(){
chars[100]="1a2a3s4dff5fj6u7M8B9P0O1U2";
chart[150],u[100];
printf("s=%s ",s);
encode_string(s,strlen(s),t);
printf("t=%s ",t);
decode_string(t,u);
printf("u=%s ",u);
return0;
}

『貳』 java加密的幾種方式

朋友你好,很高興為你作答。

首先,Java加密能夠應對的風險包括以下幾個:

1、核心技術竊取

2、核心業務破解

3、通信模塊破解

4、API介面暴露

本人正在使用幾維安全Java加密方式,很不錯,向你推薦,希望能夠幫助到你。

幾維安全Java2C針對DEX文件進行加密保護,將DEX文件中標記的Java代碼翻譯為C代碼,編譯成加固後的SO文件。默認情況只加密activity中的onCreate函數,如果開發者想加密其它類和方法,只需對相關類或函數添加標記代碼,在APK加密時會自動對標記的代碼進行加密處理。

與傳統的APP加固方案相比,不涉及到自定義修改DEX文件的載入方式,所以其兼容性非常好;其次Java函數被完全轉化為C函數,直接在Native層執行,不存在Java層解密執行的步驟,其性能和執行效率更優。

如果操作上有不明白的地方,可以聯系技術支持人員幫你完成Java加密。

希望以上解答能夠幫助到你。

『叄』 php的BASE64轉碼是否和JAVA,C等其他語言的BASE64轉碼不一樣

只要是base64都是一樣的,不過有些好像在最後要加換行符。

『肆』 Base64編碼的字元串使用的RSA公鑰從C java問題,怎麼解決

import sun.misc.BASE64Encoder;
import sun.misc.BASE64Decoder;

// 將 s 進行 BASE64 編碼
public static String getBASE64(String s) {
if (s == null) return null;
return (new sun.misc.BASE64Encoder()).encode( s.getBytes() );
}

// 將 BASE64 編碼的字元串 s 進行解碼
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;
}
}

『伍』 java 把一個網路圖片轉換為base64

這個簡單啊
(1)把獲取url流轉為bitmap
(2)把bitmap再轉為base64
public static Bitmap getBitMBitmap(String urlpath) {
Bitmap map = null;
try {
URL url = new URL(urlpath);
URLConnection conn = url.openConnection();
conn.connect();
InputStream in;
in = conn.getInputStream();
map = BitmapFactory.decodeStream(in);
// TODO Auto-generated catch block
} catch (IOException e) {
e.printStackTrace();
}
return map;
}

第二步
/**
* bitmap轉為base64
* @param bitmap
* @return
*/
public static String bitmapToBase64(Bitmap bitmap) {

String result = null;
ByteArrayOutputStream baos = null;
try {
if (bitmap != null) {
baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);

baos.flush();
baos.close();

byte[] bitmapBytes = baos.toByteArray();
result = Base64.encodeToString(bitmapBytes, Base64.DEFAULT);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (baos != null) {
baos.flush();
baos.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return result;
}
有什麼問題提問就好

『陸』 javac編譯、運行問題

用-Xlint:unchecked 編譯。這樣就能忽略警告了。也可以通過@SuppressWarnings("unchecked") 來忽略檢查的。

『柒』 DES加密解密問題 java與C 通訊

經測試應該是如下問題:

1.注意取字元串bytes是編碼保持一致,c的和java的保存一直,問一下c開發用的是那個。
2.key和Iv保持一致
3.加密模式和填充方式保持一致----------------------------這點的可能性比較大
比如C#里
algo.Mode=CipherMode.ECB;
algo.Padding=PaddingMode.None;
則java里對應的為
final Cipher algo=Cipher.getInstance("DES/ECB/NoPadding");

import java.io.IOException;
import java.security.SecureRandom;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class DesUtil {

private final static String DES = "DES";

public static void main(String[] args) throws Exception {
String data = "fff";//原字元
String key = "80825cf7fedff723";//加密key
System.err.println(encrypt(data, key));
System.err.println(decrypt("FAQXWvLnsSA=", key));//進行解密「FAQXWvLnsSA=」

}

/**
* Description 根據鍵值進行加密
* @param data
* @param key 加密鍵byte數組
* @return
* @throws Exception
*/
public static String encrypt(String data, String key) throws Exception {
byte[] bt = encrypt(data.getBytes(), key.getBytes());
String strs = new BASE64Encoder().encode(bt);
return strs;
}

/**
* Description 根據鍵值進行解密
* @param data
* @param key 加密鍵byte數組
* @return
* @throws IOException
* @throws Exception
*/
public static String decrypt(String data, String key) throws IOException,
Exception {
if (data == null)
return null;
BASE64Decoder decoder = new BASE64Decoder();
byte[] buf = decoder.decodeBuffer(data);
byte[] bt = decrypt(buf,key.getBytes());
return new String(bt);
}

/**
* Description 根據鍵值進行加密
* @param data
* @param key 加密鍵byte數組
* @return
* @throws Exception
*/
private static byte[] encrypt(byte[] data, byte[] key) throws Exception {
// 生成一個可信任的隨機數源
SecureRandom sr = new SecureRandom();

// 從原始密鑰數據創建DESKeySpec對象
DESKeySpec dks = new DESKeySpec(key);

// 創建一個密鑰工廠,然後用它把DESKeySpec轉換成SecretKey對象
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
SecretKey securekey = keyFactory.generateSecret(dks);

// Cipher對象實際完成加密操作
Cipher cipher = Cipher.getInstance(DES);

// 用密鑰初始化Cipher對象
cipher.init(Cipher.ENCRYPT_MODE, securekey, sr);

return cipher.doFinal(data);
}

/**
* Description 根據鍵值進行解密
* @param data
* @param key 加密鍵byte數組
* @return
* @throws Exception
*/
private static byte[] decrypt(byte[] data, byte[] key) throws Exception {
// 生成一個可信任的隨機數源
SecureRandom sr = new SecureRandom();

// 從原始密鑰數據創建DESKeySpec對象
DESKeySpec dks = new DESKeySpec(key);

// 創建一個密鑰工廠,然後用它把DESKeySpec轉換成SecretKey對象
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
SecretKey securekey = keyFactory.generateSecret(dks);

// Cipher對象實際完成解密操作
Cipher cipher = Cipher.getInstance(DES);

// 用密鑰初始化Cipher對象
cipher.init(Cipher.DECRYPT_MODE, securekey, sr);

return cipher.doFinal(data);
}
}

『捌』 base64編碼是什麼意思啊

Base64是網路上最常見的用於傳輸8Bit位元組代碼的編碼方式之一,大家可以查看RFC2045~RFC2049,上面有MIME的詳細規范。Base64編碼可用於在HTTP環境下傳遞較長的標識信息。例如,在Java Persistence系統Hibernate中,就採用了Base64來將一個較長的唯一標識符(一般為128-bit的UUID)編碼為一個字元串,用作HTTP表單和HTTP GET URL中的參數。在其他應用程序中,也常常需要把二進制數據編碼為適合放在URL(包括隱藏表單域)中的形式。此時,採用Base64編碼具有不可讀性,即所編碼的數據不會被人用肉眼所直接看到。

『玖』 求java加密源代碼(MD5,base64)

加密什麼加密字元串嗎,我這里有md5的演算法
public final static String MD5(String pwd) {
char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F' };
try {
byte[] strTemp = pwd.getBytes();
MessageDigest mdTemp = MessageDigest.getInstance("MD5");
mdTemp.update(strTemp);
byte[] md = mdTemp.digest();
int j = md.length;
char str[] = new char[j * 2];
int k = 0;
for (int i = 0; i < j; i++) {
byte byte0 = md[i];
str[k++] = hexDigits[byte0 >>> 4 & 0xf];
str[k++] = hexDigits[byte0 & 0xf];
}
return new String(str);
} catch (Exception e) {
return null;
}
}

『拾』 JAVA怎麼將pdf的base64轉換成jpg的base64

package com.aiait.base.util;


import org.apache.pdfbox.pdmodel.PDDocument;

import org.apache.pdfbox.rendering.ImageType;

import org.apache.pdfbox.rendering.PDFRenderer;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;


import com.aiait.base.service.impl.base.SearchServiceImpl;


import org.apache.pdfbox.*;


import java.awt.image.BufferedImage;

import java.io.ByteArrayOutputStream;

import java.io.File;

import java.io.IOException;

import java.io.InputStream;

import java.net.URL;

import java.text.DecimalFormat;

import java.util.Date;


import javax.imageio.ImageIO;


import org.apache.commons.lang3.StringUtils;


import sun.misc.BASE64Decoder;

import sun.misc.BASE64Encoder;


public class PDFUtil {

// logger

private static final Logger lOGGER = LoggerFactory.getLogger(PDFUtil.class);


public static void main(String[] args) {

// pdfTojpg("C://Test//eClaimPDF//1//Others.pdf","C://Test//eClaimPDF//WrittenConfirmation.jpg");

Date timeDiffE = null;

Date timeDiffL = null;

timeDiffE = new Date();

base64PdfToJpg(pdfBase64);

timeDiffL = new Date();

lOGGER.info("base64PdfToJpg use time: " + getDiffTime(timeDiffL, timeDiffE) + "s");

}

private static String base64PdfToJpg(String base64Pdf) {

String jpg_base64 = null;

int pdfdpi = 400;

BASE64Decoder decoder = new BASE64Decoder();

byte[] pdf_bytes = null;

try {

pdf_bytes = decoder.decodeBuffer(base64Pdf);

} catch (IOException e1) {

e1.printStackTrace();

}


try (final PDDocument document = PDDocument.load(pdf_bytes)) {

int size = document.getNumberOfPages();

/*圖像合並使用參數*/

// 定義寬度

int width = 0;

// 保存一張圖片中的RGB數據

int[] singleImgRGB;

// 定義高度,後面用於疊加

int shiftHeight = 0;

//保存每張圖片的像素值

BufferedImage imageResult = null;

// 利用PdfBox生成圖像

PDDocument pdDocument = document;

PDFRenderer renderer = new PDFRenderer(pdDocument);

/*根據總頁數, 按照50頁生成一張長圖片的邏輯, 進行拆分*/

// 每50頁轉成1張圖片

int pageLength = size; //有多少轉多少

// 總計循環的次數

int totalCount = pdDocument.getNumberOfPages() / pageLength + 1;

for (int m = 0; m < totalCount; m++) {

for (int i = 0; i < pageLength; i++) {

int pageIndex = i + (m * pageLength);

if (pageIndex == pdDocument.getNumberOfPages()) {

System.out.println("m = " + m);

break;

}

// 96為圖片的dpi,dpi越大,則圖片越清晰,圖片越大,轉換耗費的時間也越多

BufferedImage image = renderer.renderImageWithDPI(pageIndex, 106, ImageType.RGB);

int imageHeight = image.getHeight();

int imageWidth = image.getWidth();

if (i == 0) {

//計算高度和偏移量

//使用第一張圖片寬度;

width = imageWidth;

// 保存每頁圖片的像素值

// 加個判斷:如果m次循環後所剩的圖片總數小於pageLength,則圖片高度按剩餘的張數繪制,否則會出現長圖片下面全是黑色的情況

if ((pdDocument.getNumberOfPages() - m * pageLength) < pageLength) {

imageResult = new BufferedImage(width, imageHeight * (pdDocument.getNumberOfPages() - m * pageLength), BufferedImage.TYPE_INT_RGB);

} else {

imageResult = new BufferedImage(width, imageHeight * pageLength, BufferedImage.TYPE_INT_RGB);

}

} else {

// 將高度不斷累加

shiftHeight += imageHeight;

}

singleImgRGB = image.getRGB(0, 0, width, imageHeight, null, 0, width);

imageResult.setRGB(0, shiftHeight, width, imageHeight, singleImgRGB, 0, width);

}

// System.out.println("m = " + m);

File outFile = new File("C://Test//eClaimPDF//WrittenConfirmation.png");

System.out.println(outFile.getName());

// 寫圖片

ImageIO.write(imageResult, "png", outFile);

// 這個很重要,下面會有說明

shiftHeight = 0;

}

pdDocument.close();


ByteArrayOutputStream baos = new ByteArrayOutputStream();//io流

ImageIO.write(imageResult, "png", baos);//寫入流中

byte[] jpg_Bytes = baos.toByteArray();//轉換成位元組

BASE64Encoder encoder = new BASE64Encoder();

jpg_base64 = encoder.encodeBuffer(jpg_Bytes).trim();//轉換成base64串

jpg_base64 = jpg_base64.replaceAll(" ", "").replaceAll(" ", "");//刪除

// System.out.println("值為:"+"data:image/jpg;base64,"+jpg_base64);

} catch (Exception e) {

e.printStackTrace();

}

return "data:image/jpg;base64,"+jpg_base64;

}

// private static String base64PdfToJpg(String base64Pdf) {

// String jpg_base64 = null;

// int pdfdpi = 400;

//

// BASE64Decoder decoder = new BASE64Decoder();

// byte[] pdf_bytes = null;

// try {

// pdf_bytes = decoder.decodeBuffer(base64Pdf);

// } catch (IOException e1) {

// e1.printStackTrace();

// }

//

// try (final PDDocument document = PDDocument.load(pdf_bytes)) {

// int size = document.getNumberOfPages();

// for (int i = 0; i < size; i++) {

// BufferedImage image = new PDFRenderer(document).renderImageWithDPI(i, pdfdpi, ImageType.RGB);

// BufferedImage image = new PDFRenderer(document).

//

// ByteArrayOutputStream baos = new ByteArrayOutputStream();//io流

// ImageIO.write(image, "jpg", baos);//寫入流中

// byte[] jpg_Bytes = baos.toByteArray();//轉換成位元組

// BASE64Encoder encoder = new BASE64Encoder();

// jpg_base64 = encoder.encodeBuffer(jpg_Bytes).trim();//轉換成base64串

// jpg_base64 = jpg_base64.replaceAll(" ", "").replaceAll(" ", "");//刪除

//

// System.out.println("值為:"+"data:image/jpg;base64,"+jpg_base64);

//

// }

// } catch (Exception e) {

// e.printStackTrace();

// }

// return "data:image/jpg;base64,"+jpg_base64;

// }


private static void pdfTojpg(String pdfFilePath, String jpgFilePath) {

File pdfFile = new File(pdfFilePath);

int idx = jpgFilePath.lastIndexOf('.');

String jpgprefix = StringUtils.substring(jpgFilePath, 0, idx);

int pdfdpi = 400;

BASE64Decoder decoder = new BASE64Decoder();

byte[] bytes = null;

try {

bytes = decoder.decodeBuffer(pdfBase64);

} catch (IOException e1) {

e1.printStackTrace();

}


// try (final PDDocument document = PDDocument.load(pdfFile, "")) {

try (final PDDocument document = PDDocument.load(bytes)) {

int size = document.getNumberOfPages();

for (int i = 0; i < size; i++) {

BufferedImage image = new PDFRenderer(document).renderImageWithDPI(i, pdfdpi, ImageType.RGB);

/*

* ByteArrayOutputStream baos = new ByteArrayOutputStream();//io流

* ImageIO.write(image, "jpg", baos);//寫入流中 byte[] imgBytes =

* baos.toByteArray();//轉換成位元組 BASE64Encoder encoder = new BASE64Encoder();

* String png_base64 = encoder.encodeBuffer(imgBytes).trim();//轉換成base64串

* png_base64 = png_base64.replaceAll(" ", "").replaceAll(" ", "");//刪除

*

* System.out.println("值為:"+"data:image/jpg;base64,"+png_base64);

*/

File jpgFile = new File(jpgprefix + "_" + i + ".jpg");

ImageIO.write(image, "jpg", jpgFile);

}

} catch (Exception e) {

e.printStackTrace();

}


}

private static Double getDiffTime(Date lateTime, Date earlyTime) {

DecimalFormat df=new DecimalFormat("0.00");//設置保留位數

return Double.valueOf(df.format((double)(lateTime.getTime() - earlyTime.getTime()) / 1000));

}


public static String pdfBase64 = "***" //from web網頁鏈接, upload a PDF to get the base64 string (Base64 - Online Base64 decoder and encoder)

}

閱讀全文

與base64javac相關的資料

熱點內容
對越自衛反擊戰電影大全集免費 瀏覽:565
一起看電影網站源碼 瀏覽:909
阿甘正傳阿甘的英文名 瀏覽:159
電影天名 瀏覽:626
弱視矯治系統源碼 瀏覽:899
金融市場基礎知識pdf 瀏覽:383
三沒降頭電影 瀏覽:586
黃色武俠小說txt下載 瀏覽:531
如何將伺服器轉移至阿里平台 瀏覽:744
哪個網站可以看島國片 瀏覽:648
代駕app如何導航到起點 瀏覽:667
機器人穿越外國電影 瀏覽:681
贏在龍頭主圖指標源碼 瀏覽:951
符號加在命令後面 瀏覽:271
沙漏驗機寶檢測安卓手機怎麼樣 瀏覽:369
非洲電影有哪些好看的 瀏覽:763
媒介學pdf 瀏覽:234
推薦一個在線觀看 瀏覽:471
單片機16進制編程圖 瀏覽:490
金剛2迅雷下載 瀏覽:275