- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我编写了一个小型 Java 程序,该程序使用 BouncyCaSTLe 创建公共(public)和私有(private) RSA key ,然后使用这些 key 来加密/解密文件。我能够使用 Java 程序加密和解密文件。我还可以使用程序生成的 key 使用 OpenSSL 解密加密文件。
问题是 OpenSSL 无法加载由我的 Java 程序生成的公钥来加密数据。
我将共享我作为测试创建的公钥和私钥。我完全知道发布 key 会使它们无法用于加密目的,这些特定 key 仅用于测试!!!
Java代码:
package test;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.RandomAccessFile;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.Key;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Security;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.Base64;
import java.util.Scanner;
import javax.crypto.Cipher;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.util.io.pem.PemObject;
import org.bouncycastle.util.io.pem.PemWriter;
public class PublicKeyTest {
public static final int KEY_SIZE = 1024;
public static void main(String[] args) {
System.out.println("0. PK Encrypt File");
System.out.println("1. PK Decrypt File");
System.out.println("2. PK Generate Keys");;
Scanner scan = new Scanner(System.in);
String choicetext = scan.nextLine();
int choice = Integer.parseInt(choicetext);
if (choice == 0) {
System.out.print("Infile: ");
String inpath = scan.nextLine();
System.out.print("Outfile: ");
String outpath = scan.nextLine();
byte[] bytes = FiletoBytes(inpath);
PublicKey publicKey = readPublicKeyNative("./public.pem");
byte[] encryptedBytes = encrypt(bytes, publicKey);
BytestoFile(encryptedBytes, outpath);
} else if (choice == 1) {
System.out.print("Infile: ");
String inpath = scan.nextLine();
System.out.print("Outfile: ");
String outpath = scan.nextLine();
byte[] bytes = FiletoBytes(inpath);
PrivateKey privateKey = readPrivateKeyNative("./private.pem");
byte[] decryptedBytes = decrypt(bytes, privateKey);
BytestoFile(decryptedBytes, outpath);
} else if (choice == 2) {
System.out.print("Public: ");
String publicPath = scan.nextLine();
System.out.print("Private: ");
String privatePath = scan.nextLine();
writeKeys(publicPath, privatePath);
}
scan.close();
}
public static byte[] FiletoBytes(String path) {
byte[] bytes = null;
RandomAccessFile raf;
try {
raf = new RandomAccessFile(path, "rw");
int fileLength = (int) raf.length();
bytes = new byte[fileLength];
raf.read(bytes);
raf.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return bytes;
}
public static void BytestoFile(byte[] bytes, String path) {
RandomAccessFile raf;
try {
raf = new RandomAccessFile(path, "rw");
raf.write(bytes);
raf.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static PublicKey readPublicKeyNative(String publicKeyPath) {
Security.addProvider(new BouncyCastleProvider());
KeyFactory factory = null;
PublicKey key = null;
byte[] publicKeyFileBytes = null;
try {
publicKeyFileBytes = Files.readAllBytes(Paths.get(publicKeyPath));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String KeyString = new String(publicKeyFileBytes);
//System.out.println(KeyString);
//System.out.println("FORMATTED:");
KeyString = KeyString.replaceAll("-----BEGIN RSA PUBLIC KEY-----", "");
KeyString = KeyString.replaceAll("-----END RSA PUBLIC KEY-----", "");
KeyString = KeyString.replaceAll("[\n\r]", "");
KeyString = KeyString.trim();
//System.out.println(KeyString);
byte[] encoded = Base64.getDecoder().decode(KeyString);
// PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(encoded);
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(encoded);
try {
factory = KeyFactory.getInstance("RSA");
key = factory.generatePublic(keySpec);
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidKeySpecException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return key;
}
public static PrivateKey readPrivateKeyNative(String privateKeyPath) {
Security.addProvider(new BouncyCastleProvider());
KeyFactory factory = null;
PrivateKey key = null;
byte[] privateKeyFileBytes = null;
try {
privateKeyFileBytes = Files.readAllBytes(Paths.get(privateKeyPath));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String KeyString = new String(privateKeyFileBytes);
//System.out.println(KeyString);
//System.out.println("FORMATTED:");
KeyString = KeyString.replaceAll("-----BEGIN RSA PRIVATE KEY-----", "");
KeyString = KeyString.replaceAll("-----END RSA PRIVATE KEY-----", "");
KeyString = KeyString.replaceAll("[\n\r]", "");
KeyString = KeyString.trim();
//System.out.println(KeyString);
byte[] encoded = Base64.getDecoder().decode(KeyString);
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(encoded);
// X509EncodedKeySpec keySpec = new X509EncodedKeySpec(encoded);
try {
factory = KeyFactory.getInstance("RSA");
key = factory.generatePrivate(keySpec);
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidKeySpecException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return key;
}
public static byte[] encrypt(byte[] bytes, PublicKey key) {
byte[] cipherText = null;
try {
// get an RSA cipher object and print the provider
final Cipher cipher = Cipher.getInstance("RSA");
// encrypt the plain text using the public key
cipher.init(Cipher.ENCRYPT_MODE, key);
cipherText = cipher.doFinal(bytes);
} catch (Exception e) {
e.printStackTrace();
}
return cipherText;
}
public static byte[] decrypt(byte[] text, PrivateKey key) {
byte[] decryptedText = null;
try {
// get an RSA cipher object and print the provider
final Cipher cipher = Cipher.getInstance("RSA");
// decrypt the text using the private key
cipher.init(Cipher.DECRYPT_MODE, key);
decryptedText = cipher.doFinal(text);
} catch (Exception ex) {
ex.printStackTrace();
}
return decryptedText;
}
public static void writeKeys(String publicPath,String privatePath){
Security.addProvider(new BouncyCastleProvider());
KeyPair keyPair = generateRSAKeyPair();
RSAPrivateKey priv = (RSAPrivateKey) keyPair.getPrivate();
RSAPublicKey pub = (RSAPublicKey) keyPair.getPublic();
writePemFile(priv, "RSA PRIVATE KEY", privatePath);
writePemFile(pub, "RSA PUBLIC KEY", publicPath);
}
private static KeyPair generateRSAKeyPair(){
KeyPairGenerator generator=null;
try {
generator = KeyPairGenerator.getInstance("RSA", "BC");
} catch (NoSuchAlgorithmException | NoSuchProviderException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
SecureRandom random = new SecureRandom();
generator.initialize(KEY_SIZE, random);
KeyPair keyPair = generator.generateKeyPair();
return keyPair;
}
public static void writePemFile(Key key, String description,String filename) {
PemObject pemObject = new PemObject(description, key.getEncoded());
PemWriter pemWriter=null;
try {
pemWriter = new PemWriter(new OutputStreamWriter(
new FileOutputStream(filename)));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
pemWriter.writeObject(pemObject);
pemWriter.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
问题论证:
制作 key
[tester@testdb keytest]$ java -jar pktest.jar
0. PK Encrypt File
1. PK Decrypt File
2. PK Generate Keys
2
Public: public.pem
Private: private.pem
[tester@testdb keytest]$ cat public.pem
-----BEGIN RSA PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCBZTAOigNUeTHzEAUGh+c1XNpH
5u2ARbNYIftd4dAXL2W6iUDYk9cFCfGX4p8kBH/itgbbw6IHLiyK2f4nEdupT8p/
7vMvEqN/+fCaU05mixgEhfYzlZO9GRzK3GVZrqtzrYiF0Bkifgf/xmqHDFwtLA9y
nRNAbUjq5pAz8KyKUQIDAQAB
-----END RSA PUBLIC KEY-----
[tester@testdb keytest]$ cat private.pem
-----BEGIN RSA PRIVATE KEY-----
MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAIFlMA6KA1R5MfMQ
BQaH5zVc2kfm7YBFs1gh+13h0BcvZbqJQNiT1wUJ8ZfinyQEf+K2BtvDogcuLIrZ
/icR26lPyn/u8y8So3/58JpTTmaLGASF9jOVk70ZHMrcZVmuq3OtiIXQGSJ+B//G
aocMXC0sD3KdE0BtSOrmkDPwrIpRAgMBAAECgYAFV7o+P3CXwlFPqe+rL11alLTm
lyBjVX1sPCr222YOLwTSSOyGhMQyDxEMpmzPvefR4pYx6Mf95+gq64lU76XULrj5
+wxlQVj6imMJUSWo5j85TBvcCinzMMylFIiwoZkpjPtmEFznmUcUP3BBCdn6qxIq
3STQGnevExbzKaDpiQJBAMvHJZqSO6Q276Lg6G5jw+k4Ynjk5Z2AWVBBsBEkTcn7
9XBRrQW42gPmN5M7kPI2IQSb4Kjb+rq4kmV2e85vPh8CQQCijip1E4kevrDxr2pb
FHI0Ht86jrx3CTvKYpb+LE/7OI+h+RDRqeOcgP/HSWfOjtH3sRG8PZZeYsolVOr5
7kmPAkA578gAN31fhgMB8yICaLkFsPNGXgXujtRV3ic56HF5cPpqUb54twK9QxIf
+TqPstYWYl8wg0K5Hcr5sAMpQTWPAkAcIn0IvHPcJWccvZ6r2vMVQE6kpPXLqIZ3
te6qWWMSeSyq/R/DGiNyAAXFKVhVMPT4aOZH7WTsOy7/nR36WhrTAkBGP7NfsCGd
wtsfH9n9h1xCBamTguF7XjXELEymfbW+OFbQRYMdu3G2a+yZuswjicoenw5kNLFm
zblu/SZSYUOB
-----END RSA PRIVATE KEY-----
[tester@testdb keytest]$
创建带有 secret 消息的文件
[tester@testdb keytest]$ echo "secret" > testfile.txt
[tester@testdb keytest]$ cat testfile.txt
secret
使用Java程序加密文件
[tester@testdb keytest]$ java -jar pktest.jar
0. PK Encrypt File
1. PK Decrypt File
2. PK Generate Keys
0
Infile: testfile.txt
Outfile: testfile_encrypted.txt
[tester@testdb keytest]$ cat testfile_encrypted.txt
~!▒▒
d]`▒g)▒▒▒▒m▒▒Y2▒ؐ▒▒t▒▒⦱▒n▒▒vi▒i▒▒]▒(ʬ▒S▒▒▒▒II▒▒▒19▒▒[~8▒1▒R▒`▒▒q▒▒0d▒#
▒▒
▒ͬ6j▒SF▒s▒▒▒▒R.m▒u▒Q▒V▒rS▒▒T[tester@testdb keytest]$
用Java程序解密文件
[tester@testdb keytest]$ java -jar pktest.jar
0. PK Encrypt File
1. PK Decrypt File
2. PK Generate Keys
1
Infile: testfile_encrypted.txt
Outfile: testfile_decrypted.txt
[tester@testdb keytest]$ cat testfile_decrypted.txt
secret
[tester@testdb keytest]$
使用 OpenSSL 测试解密文件
[tester@testdb keytest]$ cat testfile_encrypted.txt |openssl rsautl -decrypt -inkey private.pem
secret
测试使用 OpenSSL 加密单独的文件(失败)
[tester@testdb keytest]$ cat testfile2.txt
secret2
[tester@testdb keytest]$ cat testfile2.txt |openssl rsautl -encrypt -pubin -inkey public.pem > testfile2_encrypted.txt
unable to load Public Key
尝试添加 -inform PEM 失败,OpenSSL 提供语法帮助页面
[tester@testdb keytest]$ cat testfile2.txt |openssl rsautl -encrypt -pubin -inform PEM -inkey public.pem > testfile2_encrypted.txt
Usage: rsautl [options]
-in file input file
-out file output file
-inkey file input key
-keyform arg private key format - default PEM
-pubin input is an RSA public
-certin input is a certificate carrying an RSA public key
-ssl use SSL v2 padding
-raw use no padding
-pkcs use PKCS#1 v1.5 padding (default)
-oaep use PKCS#1 OAEP
-sign sign with private key
-verify verify with public key
-encrypt encrypt with public key
-decrypt decrypt with private key
-hexdump hex dump output
-engine e use engine e, possibly a hardware device.
-passin arg pass phrase source
更改页眉和页脚似乎不起作用
[tester@testdb keytest]$ cat testfile2.txt |openssl rsautl -encrypt -pubin -inkey public.pem > testfile2_encrypted.txt
unable to load Public Key
[tester@testdb keytest]$ cat public2.pem
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCBZTAOigNUeTHzEAUGh+c1XNpH
5u2ARbNYIftd4dAXL2W6iUDYk9cFCfGX4p8kBH/itgbbw6IHLiyK2f4nEdupT8p/
7vMvEqN/+fCaU05mixgEhfYzlZO9GRzK3GVZrqtzrYiF0Bkifgf/xmqHDFwtLA9y
nRNAbUjq5pAz8KyKUQIDAQAB
-----END PUBLIC KEY-----
尝试使用 -RSAPublicKey_in 转换公钥也失败了
[tester@testdb keytest]$ openssl rsa -inform PEM -outform -PEM -RSAPublicKey_in -in public.pem -out public2.pem
unable to load Public Key
139808815384480:error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag:tasn_dec.c:1319:
139808815384480:error:0D06C03A:asn1 encoding routines:ASN1_D2I_EX_PRIMITIVE:nested asn1 error:tasn_dec.c:831:
139808815384480:error:0D08303A:asn1 encoding routines:ASN1_TEMPLATE_NOEXP_D2I:nested asn1 error:tasn_dec.c:751:Field=n, Type=RSA
139808815384480:error:0906700D:PEM routines:PEM_ASN1_read_bio:ASN1 lib:pem_oth.c:83:
Per jww 从页眉和页脚中删除 RSA 并使用“-keyform PEM”传递 key 有效
为什么我必须进行这些更改?有什么方法可以让 BouncyCaSTLe 以 OpenSSL 获取公钥的方式输出 PEM 文件,而无需强制我进行这些更改。
[tester@testdb keytest]$ cat testfile2.txt |openssl rsautl -encrypt -pubin -inkey public^Cem -keyform PEM > testfile2_encrypted.txt
[tester@testdb keytest]$ cat public2.pem
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCBZTAOigNUeTHzEAUGh+c1XNpH
5u2ARbNYIftd4dAXL2W6iUDYk9cFCfGX4p8kBH/itgbbw6IHLiyK2f4nEdupT8p/
7vMvEqN/+fCaU05mixgEhfYzlZO9GRzK3GVZrqtzrYiF0Bkifgf/xmqHDFwtLA9y
nRNAbUjq5pAz8KyKUQIDAQAB
-----END PUBLIC KEY-----
[tester@testdb keytest]$ cat testfile2.txt |openssl rsautl -encrypt -pubin -inkey public2.pem -keyform PEM > testfile2_encrypted.txt
[tester@testdb keytest]$ cat testfile2_encrypted.txt |openssl rsautl -decrypt -inkey private.pem > testfile2_decrypted.txt
为什么我会收到此无法加载公钥错误?
最佳答案
我遇到这个问题的原因是我通过 BouncyCaSTLe API 创建公钥和私钥(特别是公钥)的方式。我在我的 writeKeys
中将 keyPair.getPrivate(); 返回的对象转换为 RSAPrivateKey旧代码:
public static void writeKeys(String publicPath,String privatePath){
Security.addProvider(new BouncyCastleProvider());
KeyPair keyPair = generateRSAKeyPair();
RSAPrivateKey priv = (RSAPrivateKey) keyPair.getPrivate();
RSAPublicKey pub = (RSAPublicKey) keyPair.getPublic();
writePemFile(priv, "RSA PRIVATE KEY", privatePath);
writePemFile(pub, "RSA PUBLIC KEY", publicPath);
}
新代码:
public static void writeKeys(String publicPath, String privatePath) {
Security.addProvider(new BouncyCastleProvider());
KeyPair keyPair = generateRSAKeyPair();
PrivateKey priv = keyPair.getPrivate();
PublicKey pub = keyPair.getPublic();
writePemFile(priv, "PRIVATE KEY", privatePath);
writePemFile(pub, "PUBLIC KEY", publicPath);
}
当然,更改此方法后,我还必须修改我的两个读取私钥和公钥的方法,以便删除新的页眉/页脚。
旧代码:
public static PublicKey readPublicKeyNative(String publicKeyPath) {
Security.addProvider(new BouncyCastleProvider());
KeyFactory factory = null;
PublicKey key = null;
byte[] publicKeyFileBytes = null;
try {
publicKeyFileBytes = Files.readAllBytes(Paths.get(publicKeyPath));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String KeyString = new String(publicKeyFileBytes);
//System.out.println(KeyString);
//System.out.println("FORMATTED:");
KeyString = KeyString.replaceAll("-----BEGIN RSA PUBLIC KEY-----", "");
KeyString = KeyString.replaceAll("-----END RSA PUBLIC KEY-----", "");
KeyString = KeyString.replaceAll("[\n\r]", "");
KeyString = KeyString.trim();
//System.out.println(KeyString);
byte[] encoded = Base64.getDecoder().decode(KeyString);
// PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(encoded);
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(encoded);
try {
factory = KeyFactory.getInstance("RSA");
key = factory.generatePublic(keySpec);
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidKeySpecException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return key;
}
public static PrivateKey readPrivateKeyNative(String privateKeyPath) {
Security.addProvider(new BouncyCastleProvider());
KeyFactory factory = null;
PrivateKey key = null;
byte[] privateKeyFileBytes = null;
try {
privateKeyFileBytes = Files.readAllBytes(Paths.get(privateKeyPath));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String KeyString = new String(privateKeyFileBytes);
//System.out.println(KeyString);
//System.out.println("FORMATTED:");
KeyString = KeyString.replaceAll("-----BEGIN RSA PRIVATE KEY-----", "");
KeyString = KeyString.replaceAll("-----END RSA PRIVATE KEY-----", "");
KeyString = KeyString.replaceAll("[\n\r]", "");
KeyString = KeyString.trim();
//System.out.println(KeyString);
byte[] encoded = Base64.getDecoder().decode(KeyString);
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(encoded);
// X509EncodedKeySpec keySpec = new X509EncodedKeySpec(encoded);
try {
factory = KeyFactory.getInstance("RSA");
key = factory.generatePrivate(keySpec);
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidKeySpecException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return key;
}
新代码:
public static PublicKey readPublicKeyNative(String publicKeyPath) {
Security.addProvider(new BouncyCastleProvider());
KeyFactory factory = null;
PublicKey key = null;
byte[] publicKeyFileBytes = null;
try {
publicKeyFileBytes = Files.readAllBytes(Paths.get(publicKeyPath));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String KeyString = new String(publicKeyFileBytes);
KeyString = KeyString.replaceAll("-----BEGIN PUBLIC KEY-----", "");
KeyString = KeyString.replaceAll("-----END PUBLIC KEY-----", "");
KeyString = KeyString.replaceAll("[\n\r]", "");
KeyString = KeyString.trim();
byte[] encoded = Base64.getDecoder().decode(KeyString);
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(encoded);
try {
factory = KeyFactory.getInstance("RSA");
key = factory.generatePublic(keySpec);
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidKeySpecException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return key;
}
public static PrivateKey readPrivateKeyNative(String privateKeyPath) {
Security.addProvider(new BouncyCastleProvider());
KeyFactory factory = null;
PrivateKey key = null;
byte[] privateKeyFileBytes = null;
try {
privateKeyFileBytes = Files.readAllBytes(Paths.get(privateKeyPath));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String KeyString = new String(privateKeyFileBytes);
KeyString = KeyString.replaceAll("-----BEGIN PRIVATE KEY-----", "");
KeyString = KeyString.replaceAll("-----END PRIVATE KEY-----", "");
KeyString = KeyString.replaceAll("[\n\r]", "");
KeyString = KeyString.trim();
byte[] encoded = Base64.getDecoder().decode(KeyString);
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(encoded);
try {
factory = KeyFactory.getInstance("RSA");
key = factory.generatePrivate(keySpec);
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidKeySpecException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return key;
}
感谢大家的帮助!
关于java - 无法使用公共(public) RSA key (使用 bouncycaSTLe 创建的 PEM 文件)加密文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29221947/
前言: 有时候,一个数据库有多个帐号,包括数据库管理员,开发人员,运维支撑人员等,可能有很多帐号都有比较大的权限,例如DDL操作权限(创建,修改,删除存储过程,创建,修改,删除表等),账户多了,管理
所以我用 Create React App 创建并设置了一个大型 React 应用程序。最近我们开始使用 Storybook 来处理和创建组件。它很棒。但是,当我们尝试运行或构建应用程序时,我们不断遇
遵循我正在创建的控件的代码片段。这个控件用在不同的地方,变量也不同。 我正在尝试编写指令来清理代码,但在 {{}} 附近插入值时出现解析错误。 刚接触 Angular ,无法确定我错过了什么。请帮忙。
我正在尝试创建一个 image/jpeg jax-rs 提供程序类,它为我的基于 post rest 的 Web 服务创建一个图像。我无法制定请求来测试以下内容,最简单的测试方法是什么? @POST
我一直在 Windows 10 的模拟器中练习 c。后来我改用dev C++ IDE。当我在 C 中使用 FILE 时。创建的文件的名称为 test.txt ,而我给出了其他名称。请帮助解决它。 下面
当我们创建自定义 View 时,我们将 View 文件的所有者设置为自定义类,并使用 initWithFrame 或 initWithCode 对其进行实例化。 当我们创建 customUITable
我正在尝试为函数 * Producer 创建一个线程,但用于创建线程的行显示错误。我为这句话加了星标,但我无法弄清楚它出了什么问题...... #include #include #include
今天在做项目时,遇到了需要创建JavaScript对象的情况。所以Bing了一篇老外写的关于3种创建JavaScript对象的文章,看后跟着打了一遍代码。感觉方法挺好的,在这里与大家分享一下。 &
我正在阅读将查询字符串传递给 Amazon 的 S3 以进行身份验证的文档,但似乎无法理解 StringToSign 的创建和使用方式。我正在寻找一个具体示例来说明 (1) 如何构造 String
前言:我对 C# 中任务的底层实现不太了解,只了解它们的用法。为我在下面屠宰的任何东西道歉: 对于“我怎样才能开始一项任务但不等待它?”这个问题,我找不到一个好的答案。在 C# 中。更具体地说,即使任
我有一个由一些复杂的表达式生成的 ILookup。假设这是按姓氏查找人。 (在我们简单的世界模型中,姓氏在家庭中是唯一的) ILookup families; 现在我有两个对如何构建感兴趣的查询。 首
我试图创建一个 MSI,其中包含 和 exe。在 WIX 中使用了捆绑选项。这样做时出错。有人可以帮我解决这个问题。下面是代码: 错误 error LGH
在 Yii 中,Create 和 Update 通常使用相同的形式。因此,如果我在创建期间有电子邮件、密码、...other_fields...等字段,但我不想在更新期间专门显示电子邮件和密码字段,但
上周我一直在努力创建一个给定一行和一列的 QModelIndex。 或者,我会满足于在已经存在的 QModelIndex 中更改 row() 的值。 任何帮助,将不胜感激。 编辑: QModelInd
出于某种原因,这不起作用: const char * str_reset_command = "\r\nReset"; const char * str_config_command = "\r\nC
现在,我有以下由 original.df %.% group_by(Category) %.% tally() %.% arrange(desc(n)) 创建的 data.frame。 DF 5),
在今天之前,我使用/etc/vim/vimrc来配置我的vim设置。今天,我想到了创建.vimrc文件。所以,我用 touch .vimrc cat /etc/vim/vimrc > .vimrc 所
我可以创建一个 MKAnnotation,还是只读的?我有坐标,但我发现使用 setCooperative 手动创建 MKAnnotation 并不容易。 想法? 最佳答案 MKAnnotation
在以下代码中,第一个日志语句按预期显示小数,但第二个日志语句记录 NULL。我做错了什么? NSDictionary *entry = [[NSDictionary alloc] initWithOb
我正在使用与此类似的代码动态添加到数组; $arrayF[$f+1][$y][$x+1] = $value+1; 但是我在错误报告中收到了这个: undefined offset :1 问题:尝试创
我是一名优秀的程序员,十分优秀!