导航:首页 > 编程语言 > 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相关的资料

热点内容
苹果开机白屏带文件夹问号 浏览:731
体验服为什么服务器会关闭 浏览:39
酒店命令 浏览:750
中走丝线切割编程视频 浏览:78
衣服压缩袋手泵原理 浏览:714
通达信编程书籍 浏览:981
车用压缩天然气瓶阀 浏览:971
鞋的程序员 浏览:259
车的压缩比是什么意思 浏览:202
网站源码怎么传到文件夹 浏览:914
海南压缩机在哪里 浏览:491
电脑文件夹清晰的文件结构 浏览:839
如何把苹果手机的app转到安卓 浏览:305
java同步并发 浏览:249
fw压缩图片 浏览:258
淘宝申请源码靠谱吗 浏览:874
androidupdater 浏览:635
c2d游戏源码大全可复制版 浏览:771
电脑怎样重置网关命令 浏览:411
winftplinux 浏览:335